[comp.lang.c] Prototypes for macros?

gleeper@tybalt.caltech.edu (Evan Manning) (05/04/90)

I ran into an interesting situation yesterday playing with my brand
new Turbo C 2.0.  I was trying to use it with all warnings and errors
enabled, as I'd heard it claimed that this obviated all need for lint
(At my previous job I got quite attached to PC-Lint from Gimpel but now
it's my money so I thought I'd at least give Turbo a chance.)

The problem emerged when I tried to use some functions (randomize &
random) which are defined as macros in the headers.  TC gave me a
'no prototype in scope' warning and then some other error message I
don't recall when I disabled the prototype warning.  All problems
vanished when I slavishly copied the definitions of the macros from
the header.

Is it a bug?  Should macros have prototypes too?  Will I have to worry
about putchar et al?

-- Evan

***************************************************************************
Your eyes are weary from staring at the CRT for so | Evan M. Manning
long.  You feel sleepy.  Notice how restful it is  |      is
to watch the cursor blink.  Close your eyes.  The  | gleeper@tybalt.caltech.edu
opinions stated above are yours.  You cannot       | manning@mars.jpl.nasa.gov
imagine why you ever felt otherwise.               |

dan@kfw.COM (Dan Mick) (05/04/90)

In article <1990May3.202403.10140@laguna.ccsf.caltech.edu> gleeper@tybalt.caltech.edu (Evan Manning) writes:
>I ran into an interesting situation yesterday playing with my brand
>new Turbo C 2.0.  I was trying to use it with all warnings and errors
>enabled, as I'd heard it claimed that this obviated all need for lint
>(At my previous job I got quite attached to PC-Lint from Gimpel but now
>it's my money so I thought I'd at least give Turbo a chance.)
>
>The problem emerged when I tried to use some functions (randomize &
>random) which are defined as macros in the headers.  TC gave me a
>'no prototype in scope' warning and then some other error message I
>don't recall when I disabled the prototype warning.  All problems
>vanished when I slavishly copied the definitions of the macros from
>the header.
>
>Is it a bug?  Should macros have prototypes too?  Will I have to worry
>about putchar et al?

Erm...if you had included the header, there wouldn't have been a warning,
since, after it was preprocessed, there would be no "function" randomize()
or random() to complain about.

#include <stdlib.h>

gleeper@tybalt.caltech.edu (Evan Manning) (05/04/90)

dan@kfw.COM (Dan Mick) writes:

>In article <1990May3.202403.10140@laguna.ccsf.caltech.edu> gleeper@tybalt.caltech.edu (Evan Manning) writes:
>>I ran into an interesting situation yesterday playing with my brand
>>new Turbo C 2.0.  I was trying to use it with all warnings and errors
>>enabled, as I'd heard it claimed that this obviated all need for lint
>>(At my previous job I got quite attached to PC-Lint from Gimpel but now
>>it's my money so I thought I'd at least give Turbo a chance.)
>>
>>The problem emerged when I tried to use some functions (randomize &
>>random) which are defined as macros in the headers.  TC gave me a
>>'no prototype in scope' warning and then some other error message I
>>don't recall when I disabled the prototype warning.  All problems
>>vanished when I slavishly copied the definitions of the macros from
>>the header.
>>
>>Is it a bug?  Should macros have prototypes too?  Will I have to worry
>>about putchar et al?

>Erm...if you had included the header, there wouldn't have been a warning,
>since, after it was preprocessed, there would be no "function" randomize()
>or random() to complain about.

>#include <stdlib.h>

I guess I should have mentioned that I'm not a rank amateur.  All
appropriate headers were included (including time.h for seeding off
the time in randomize()) and these are the precise same headers needed
to avoid warnings after manually expanding macros.  My guess is that
Turbo is checking for prototypes *before* expanding macros.  Which
sounds wrong to me.  Has anybody encountered this before?

-- Evan

***************************************************************************
Your eyes are weary from staring at the CRT for so | Evan M. Manning
long.  You feel sleepy.  Notice how restful it is  |      is
to watch the cursor blink.  Close your eyes.  The  | gleeper@tybalt.caltech.edu
opinions stated above are yours.  You cannot       | manning@mars.jpl.nasa.gov
imagine why you ever felt otherwise.               |

grimlok@hubcap.clemson.edu (Mike Percy) (05/05/90)

From article <1990May4.162637.29981@laguna.ccsf.caltech.edu>, by gleeper@tybalt.caltech.edu (Evan Manning):
] dan@kfw.COM (Dan Mick) writes:
] 
]>In article <1990May3.202403.10140@laguna.ccsf.caltech.edu> gleeper@tybalt.caltech.edu (Evan Manning) writes:
]>>I ran into an interesting situation yesterday playing with my brand
]>>new Turbo C 2.0.  I was trying to use it with all warnings and errors
]>>enabled, as I'd heard it claimed that this obviated all need for lint
]>>(At my previous job I got quite attached to PC-Lint from Gimpel but now
]>>it's my money so I thought I'd at least give Turbo a chance.)
]>>
]>>The problem emerged when I tried to use some functions (randomize &
]>>random) which are defined as macros in the headers.  TC gave me a
]>>'no prototype in scope' warning and then some other error message I
]>>don't recall when I disabled the prototype warning.  All problems
]>>vanished when I slavishly copied the definitions of the macros from
]>>the header.
]>>
]>>Is it a bug?  Should macros have prototypes too?  Will I have to worry
]>>about putchar et al?
] 
]>Erm...if you had included the header, there wouldn't have been a warning,
]>since, after it was preprocessed, there would be no "function" randomize()
]>or random() to complain about.
] 
]>#include <stdlib.h>
] 
] I guess I should have mentioned that I'm not a rank amateur.  All
] appropriate headers were included (including time.h for seeding off
] the time in randomize()) and these are the precise same headers needed
] to avoid warnings after manually expanding macros.  My guess is that
] Turbo is checking for prototypes *before* expanding macros.  Which
] sounds wrong to me.  Has anybody encountered this before?

Are you compiling with the -A flag set?  The one that compiles in STDC
mode?  If so, a lot of the stuff in the header files is _not_ included,
because it's not allowed to be there (by the ANSI standard).  Check to
see if the functions you are having prototype problems with are being
excluded by a #if !__STDC__ test.           

Prototyping has saved me lots of work hunting things down, so I use it
heavily, and have not had any problems.  But I haven't compiled under
STDC settings.

dan@kfw.COM (Dan Mick) (05/08/90)

In article <1990May4.162637.29981@laguna.ccsf.caltech.edu> gleeper@tybalt.caltech.edu (Evan Manning) writes:
>I guess I should have mentioned that I'm not a rank amateur.  

That, or not been so frigging touchy.  Sheesh.

>All
>appropriate headers were included (including time.h for seeding off
>the time in randomize()) and these are the precise same headers needed
>to avoid warnings after manually expanding macros.  My guess is that
>Turbo is checking for prototypes *before* expanding macros.  Which
>sounds wrong to me.  Has anybody encountered this before?

Well, tell ya what, Evan:  Try this test case.  It gives no warnings or
errors under TC 2.0 for me:


#include <stdlib.h>
#include <time.h>

int main(void)
{
    randomize();
    return 0;
}

Now what happens?  

BTW, for some more rank amateur suggestions that just might help, since
the problem you're having is most likely not the compiler....did you
try to reduce it to a small test case?  Did you look at stdlib.h for any
enclosing ifdefs that might rule out the prototypes you want?