[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A silly question about GCC



On Wed, Aug 02, 2000, Gilad Ben-Yossef wrote about "Re: A silly question about GCC":
> > > the kind of string RCS automagically makes for you if you ask it nicely.
> <snip>
> > >
> > > GCC (rightfuly) complains about the string not being used. GCC does
> > > offer the __attribute__ ((notused)) attribute, but it's only for
> > > fucntions, not variables. Is there any inteligent way to tell it to shut
> > > up for that specific variable? (except the obvious way of artifcially
> > > using it?)
> > 
> > volatile
> 
> GCC still complains. Any other ideas? 

You can try one of the following ugly solutions (but maybe someone will come
up with a better one). #2 is probably the better solution of the three.

1. Do something with that variable - something idiotic like passing it to
   a function (e.g., put a "strlen(stringname)" call in a function called only
   once, or something. You can also assign it to some pointer variable.

2. Don't make the variable static (file-local). When the variable is global
   C cannot complain about it being unused in the current file, because other
   files may "extern" and use it!
   Note that using the solution, the string will also end up in the resulting
   executable file, and you'll be able to do "ident" or "what" on it, which
   is probably what you want.
   Note that if the string is global, you'll need a different name for it
   for each file.

3. Some C compilers I knew had commands #ident (or something like that, I don't
   remember) that did exactly what you want, and you didn't even have to
   worry about the string name (you did something like '#ident "@(#)Hello 1.0"').
   Maybe gcc also has it?



-- 
Nadav Har'El                        |         Wednesday, Aug 2 2000, 2 Av 5760
nyh@math.technion.ac.il             |-----------------------------------------
Phone: +972-53-245868, ICQ 13349191 |Unix is simple, but it takes a genius to
http://nadav.harel.org.il           |understand its simplicity.

=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il