printf( "%d\n", __COUNTER__ );
$ gcc –version
gcc (Debian 4.3.2-1.1) 4.3.2
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ cat test.c
#include <stdlib.h>
#include <stdio.h>
int main()
{
printf("Hello world, %d!\n", __COUNTER__);
printf("Hello world, %d!\n", __COUNTER__);
printf("Hello world, %d!\n", __COUNTER__);
return 0;
}
$ gcc test.c
$ ./a.out
Hello world, 0!
Hello world, 1!
Hello world, 2!
$
[me@beast test]$ more test.c
#include <stdio.h>
int main()
{
printf( "%d\n", __COUNTER__ );
return 1;
}
[me@beast test]$ gcc -o test test.c
[me@beast test]$ ./test
0
[me@beast test]$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)
So, I'm curious if anyone knows anything in particular about any particular modes or compiler options that may need to be enabled to gain access to it; perhaps even an upgrade to gcc altogether, although I'd be surprised if an upgrade is necessary. I'm compiling under gcc version 4.2.3, a fairly recent version, and mention of the __COUNTER__ macro (from what little I've found on google) seems to go back as far as 2007/2006, perhaps even earlier than that.
As stated with much of the commentary relating to the macro, my intent is to use it alongside macro token concatenation for the creation of unique variables within various automatic code, so getting this to work is rather important to me right now. Also, if there are other ideas for doing the same or similar in other ways I'd like to hear of it as well. Using __LINE__ instead is only going to be viable so long as I only need to create one unique variable on any particular line; otherwise, that method pretty much falls apart.
Help? :sad: