local macro 'Symbol' (Location) not referenced

L

Linny

Hi,
I have picked this piece of code(slightly modified) from one of gimpel
software's lint page "bug of the month"

#include <stdio.h>
#define ON_THE_ROCKS

const char *ice()
{
#if defined(SHAKEN_NOT_STIRRED)
return "shaken not stirred";
#elif defined(STIRRED_NOT_SHAKEN)
return "stirred not shaken";
#elif defined(ON_THE_ROCKS)
return "on the rocks";
#else
return "";
#endif
}

int main()
{
int i;
printf( "Celebrate the New Year " );
printf( "with your drink %s.\n", ice() );
return 0;
}

The output after compiling with gcc(Dev C++) and execution was
"Celebrate the New Year with your drink ." and not "Celebrate the New
Year with your drink on the rocks" as I expected.


The Reference Manual Explanation given was
750 local macro 'Symbol' (Location) not referenced -- A 'local'
macro is one that is not defined in a header file. The macro
was
not referenced throughout the module in which it is defined.

I am unable to follow the explanation as I tried including the macro in
a header file but got the same result. Am I missing something ? Can
anyone please explain in detail.
 
J

Jens Thoms Toerring

Linny said:
I have picked this piece of code(slightly modified) from one of gimpel
software's lint page "bug of the month"
#include <stdio.h>
#define ON_THE_ROCKS
const char *ice()
{
#if defined(SHAKEN_NOT_STIRRED)
return "shaken not stirred";
#elif defined(STIRRED_NOT_SHAKEN)
return "stirred not shaken";
#elif defined(ON_THE_ROCKS)
return "on the rocks";
#else
return "";
#endif
}
int main()
{
int i;
printf( "Celebrate the New Year " );
printf( "with your drink %s.\n", ice() );
return 0;
}
The output after compiling with gcc(Dev C++) and execution was
"Celebrate the New Year with your drink ." and not "Celebrate the New
Year with your drink on the rocks" as I expected.

The Reference Manual Explanation given was
750 local macro 'Symbol' (Location) not referenced -- A 'local'
macro is one that is not defined in a header file. The macro
was
not referenced throughout the module in which it is defined.
I am unable to follow the explanation as I tried including the macro in
a header file but got the same result. Am I missing something ? Can
anyone please explain in detail.

All you're missing is that in the program from the website

http://www.gimpel.com/html/bugs/bug750.htm

in 'ON_THE_ROCKS' the 'O' in 'ROCKS' is a character 'O' when the
macro is defined, but in the test there's the number '0' instead,
so also this test fails and the function returns the empty string.
You seem to have not used copy-and-pasted the program and removed
the bug when you typed it in.
Regards, Jens
 
L

Linny

Jens said:
All you're missing is that in the program from the website

http://www.gimpel.com/html/bugs/bug750.htm

in 'ON_THE_ROCKS' the 'O' in 'ROCKS' is a character 'O' when the
macro is defined, but in the test there's the number '0' instead,
so also this test fails and the function returns the empty string.
You seem to have not used copy-and-pasted the program and removed
the bug when you typed it in.
Regards, Jens

Thanks a Lot Jens... you are right
I missed it completely.....What a waste of time !!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top