Newer gcc swallow version control keywords

Newer gcc swallow version control keywords

Oleg Goldshmidt pub at goldshmidt.org
Mon Oct 17 23:04:26 IST 2011


"Nadav Har'El" <nyh at math.technion.ac.il> writes:

> 	#if (__GNUC__ >= 4) && (__GNUC_MINOR__ > 4)
> 	#define USED(x) x __attribute__((used))
> 	#else
> 	#define USED(x) x
> 	#endif
> 	#define IDENT(x) static const char USED(foo_src_id[]) = x;
>
> and then in each file just do
> #include "ident.h"
> IDENT("$Id");

The proper contents of ident.h would actually be

#ifndef _IDENT_H_
#define _IDENT_H_

#if defined(__GNUC__)
#define USED(x) x __attribute__((used))
#else
#define USED(x) x
#endif

#define IDENT(s,x) static const char USED(s[]) = x

#endif

- this is because one would want to use different identifiers in every
file to avoid a) clashes when keywords are used in header files (very
useful: which versions of the headers was this file compiled with?) and
b) possible effects of -fmerge-constants and friends.

-- 
Oleg Goldshmidt | pub at goldshmidt.org



More information about the Linux-il mailing list