Skip to content

Instantly share code, notes, and snippets.

@Keith-S-Thompson
Keith-S-Thompson / README.md
Last active August 29, 2015 14:07
gcc/clang pointer equality bug demo

I believe I've found a bug in the implementation of the "==" operator for pointers in both gcc and clang.

pointer_equality_bug.c is a demonstration of the bug.

Quoting N1570 6.5.9p6:

Two pointers compare equal if and only if both are null pointers,

@Keith-S-Thompson
Keith-S-Thompson / README.md
Last active August 29, 2015 14:06
g++ bug demo
@Keith-S-Thompson
Keith-S-Thompson / README.md
Last active August 29, 2015 14:03
clang _Generic bug
#include <stdio.h>
#include <stdint.h>
int main(void) {
int64_t u = 0;
int i;
for(i=0;i<44;i++)
u |= (uint64_t)1 << i;
/*
* In response to http://stackoverflow.com/a/22918463/827263
* "In C you can't declare variables/functions (in same scope) with the same name more than once."
*/
#include <stdio.h>
void yes_you_can(void);
void yes_you_can(void);
void yes_you_can(void);
@Keith-S-Thompson
Keith-S-Thompson / README.md
Created February 15, 2014 00:43
Markdown sandbox

One hash

Two hashes

Three hashes

Four hashes

Five hashes
@Keith-S-Thompson
Keith-S-Thompson / README.md
Last active March 22, 2023 03:06
Discussion of korn.c, 1987 IOCCC entry, mentioned in http://stackoverflow.com/a/19214007/827263

korn.c is the "Best One Liner" winner of the 1987 International Obfuscated C Code Contest, by David Korn (yes, the author of the Korn Shell).

korn.hint, as the name implies, offers some hints.

A commenter on Stack Overflow asked for some clarification. I didn't want to post spoilers on the site, so I'm posting them here instead. If you haven't already (and if you're familiar with the rules of C) I encourage you to study the program for a while first.

=====

Here's the code:

/*
* Test program based on code in the Wikipedia POSIX Threads
* article, https://en.wikipedia.org/wiki/POSIX_Threads.
*
* Demo for http://stackoverflow.com/q/19128948/827263
*/
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <iostream>
using namespace std;
int agenext (int age);
int main ()
{
int age = 42;
cout << "age = " << age << "\n";
agenext(age);
@Keith-S-Thompson
Keith-S-Thompson / post.txt
Created August 26, 2013 17:43
Google Groups mangles followups
From nobody Mon Aug 26 10:42:03 2013
X-Received: by 10.224.13.136 with SMTP id c8mr16375654qaa.0.1377533997489;
Mon, 26 Aug 2013 09:19:57 -0700 (PDT)
X-Received: by 10.50.80.78 with SMTP id p14mr380876igx.6.1377533997453; Mon,
26 Aug 2013 09:19:57 -0700 (PDT)
Path: eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!npeer01.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!fx3no4866766qab.0!news-out.google.com!he10ni3708qab.0!nntp.google.com!fx3no4866762qab.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Mon, 26 Aug 2013 09:19:57 -0700 (PDT)
In-Reply-To: <lnk3j8l9xl.fsf@nuthaus.mib.org>
Complaints-To: groups-abuse@google.com