Trying to redefine __attribute__
is the wrong approach here, I think.
Anything with __
in its name is typically something gunky or low-level or implementation-dependent that you probably shouldn't be using directly in your code.
So, if for no other reason than to keep (the bulk of) your code clean, you should probably be doing things like, for example:
#define PUREFUNCTION __attribute__(pure)
Then when you have a pure function to define, rather than using __attribute__
directly, you use your new macro:
PUREFUNCTION
double mysqrt(double x)
{
...
}
And then, when the time comes to compile your code under something other than gcc, rather than trying to kludgily redefine __attribute__
, you just redefine your PUREFUNCTION
macro. You can redefine it to some other compiler-specific attribute modifier, or if there isn't one, you can define it to be nothing:
#define PUREFUNCTION
and then you won't get any compilation errors on your functions tagged as PUREFUNCTION
. (Obviously you won't be able to tag them as "pure", either, but if the compiler in question has no way to, then presumably there's no way to.)
c
andvisual-c++
tags are specified? The most suitable answer can differ for each, and usually it doesn't make sense to mixc
andc++
tags.