On 2006-08-21 14:36:05 +0200, Harald van Dijk <> said:
> That's not allowed in standard C. It's covered by 7.1.3p2:
> "No other identifiers are reserved. If the program declares or defines an
> identifier in a context in which it is reserved (other than as allowed by
> 7.1.4), or defines a reserved identifier as a macro name, the behavior is
> undefined."
> And more practically, defining a macro with the same name as a standard
> library function can break other macros which try to call the standard
> function.
Can you clarify the statement above? Read next:
>> I'm sorry; I do not understand your questions. In the first
>> part you seem to be talking of two different kinds of "definition,"
>> and I'm not sure what each refers to. "Use it in a source file" is
>> also confusing: First, it's not clear what "it" means, and second,
>> where but in a source file could you use *any* C construct?
> I'm confused as well, the best I can come up with is:
>
> x1.c:
> #define printf dummy
> extern void printf(void);
> int main(void) {
> printf();
> }
>
> x2.c:
> #include <stdio.h>
> void dummy(void) {
> puts("Hello, world!");
> }
>
> If this is meant, I don't see anything disallowing it. It's extremely poor
> style, but not invalid.
Yes, That's what I meant, using the #define inside a source file just
the way you wrote. I know it's poor, but it's what I found
Clarifying my concerns, I have a non standard C library that hasn't all
the functions it should, in the example code I found that since, for
instance, they have no printf or strlen, they use precompiler magic:
#include <stdio.h>
#define printf _sdk_PRINT_TO_FOO
#define strlen _sdk_STRING_LENGTH_BAR
int main(void)
{
printf("Hello, world!\n");
return 0;
}
The #defines are *inside* the application code, not in the libc. The
(pseudo)libc code has _sdk_PRINT_TO_FOO and _sdk_STRING_LENGTH_BAR
correclty (I hope) working though. I found this source quite weird, and
I didn't know about the legality of such definitions.
--
Sensei <>
The optimist thinks this is the best of all possible worlds.
The pessimist fears it is true. [J. Robert Oppenheimer]