On 1/16/2011 3:08 PM, Richard Sanders wrote:
> On Sun, 16 Jan 2011 08:30:01 -0500, Eric Sosman
> <> wrote:
>
>> On 1/16/2011 3:59 AM, Richard Sanders wrote:
>>> On Sat, 15 Jan 2011 09:58:42 -0800 (PST), hqin<>
>>> wrote:
>>>
>>>> Here is the compiling error:
>>>>
>>>> ace:src hqin$ make
>>>> gcc -O3 -Wall -c -o misc.o misc.c
>>>> In file included from misc.c:21:
>>>> misc.h:106: error: conflicting types for ‘psort’
>>>> /usr/include/stdlib.h:310: error: previous declaration of ‘psort’ was
>>>> here
>>>> misc.c:748: error: conflicting types for ‘psort’
>>>> /usr/include/stdlib.h:310: error: previous declaration of ‘psort’ was
>>>> here
>>>> make: *** [misc.o] Error 1
>>>
>>>
>>> After the
>>>
>>> #include<stdlib.h>
>>>
>>> add
>>>
>>> #undef psort
>>>
>>> and then
>>>
>>> #include "misc.h"
>>>
>>> The "#undef psort" stops the psort being referenced from “stdlib.h”
>>> so it can be referenced from "misc.h" and that makes for a happy
>>> compiler.
>>
>> It might be worth a try, but I doubt it will help. From the
>> wording of the error messages, it looks like `psort' has been
>> declared as an ordinary identifier, not as (or not only as) a
>> macro. The #undef will erase a macro definition, if there is
>> one, but will not affect the visibility of the plain identifier:
>>
>> int x;
>> #undef x
>> double x; // error, despite the #undef
>
> You are trying to undef a variable not a function.
#undef does not apply to variables nor to functions, but to
macros. At the time #undef is processed (and at the time macros
are expanded), there is no difference between a "variable" and
a "function." Not even `int' has any meaning beyond than "I am a
three-character token."
> #undef psort
>
> It is called function overriding and it does work and has for me since
> my turbo c days.
I have no personal experience with Turbo C. However, no C
compiler I've ever used has processed #undef any differently for
macros whose names look like functions than for macros whose
names look like something else. Certainly no Standard-conforming
compiler has ever done so.
> Rather than ruminating just try it. The thing to remember is that the
> #undef is only valid for the source file it appeares in.
Good advice. What happened when you tried it?
--
Eric Sosman
lid