How to get Gcc 2.95 to shut up with -Wall -04 on this code. :)

T

Todd Nathan

Have ported Until 2.5.2 which is a highly portable embedded FORTH-like
language system to BeOS. Turned on -Wall cause I'm anal about cleaning
up ports if I'm doing them, and have all but ONE warning that I don't seem
to be able to get cleaned up... Simply...

printf("%-10s %12lx %1d\n", temp->NFA->name, &temp, temp->NFA->immediate);

produces a gcc2.95 warning:

prim.c: In function `display_word':
prim.c:2203: warning: long unsigned int format, pointer arg (arg 3)

where temp is defined

struct DictHeader *temp;

with the of-importance struct defs:

struct NameField {
int len;
int system;
int immediate;
int smudge;
char *name;
struct view_location *view;
};

struct DictHeader {
void (*CFA)(); /* ptr to primitive function */
union pfa_type PFA; /* ptr to list of words to execute */
struct NameField *NFA; /* ptr to name string */
struct DictHeader *LFA; /* points to next word in dict. */
};

I'm rather perplexed, without -Wall the warning doesn't come on at all. So,
would someone please enlighten me on how to get the compiler to shut up :)

Thank you, please email me directly, I do not frequent this group at all.

Best wishes!
 
J

jacob navia

Todd Nathan said:
Have ported Until 2.5.2 which is a highly portable embedded FORTH-like
language system to BeOS. Turned on -Wall cause I'm anal about cleaning
up ports if I'm doing them, and have all but ONE warning that I don't seem
to be able to get cleaned up... Simply...

printf("%-10s %12lx %1d\n", temp->NFA->name, &temp, temp->NFA->immediate);

produces a gcc2.95 warning:

prim.c: In function `display_word':
prim.c:2203: warning: long unsigned int format, pointer arg (arg 3)

How to get rid of warnings:

Method 1
 
R

Richard Heathfield

Allin said:
To be a little more expansive (Richard knows all this, but didn't
choose to say it):

1) The "%p" conversion is the only standard-compliant way of printing
a pointer value. Use of one of the regular integer types implies that
you (think you) know more about the representation of pointer values
than is guaranteed by the C standard.

2) Have chosen "%p", the cast "(void *)" is required (in a notable
exception to the rule that casts in C are unneccessary if not evil)
since arguments to variadic functions such as printf() are not
subject to the usual automatic type-conversion, "%p" conversion
requires a (void *) argument, and "&temp" is not in itself a void
pointer.


Beautifully put. You have done all the typing I didn't want to do. My
thanks.
 
D

Daniel Haude

On Sun, 10 Aug 2003 00:01:41 +0200,
in Msg. said:
Richard, sorry but should be (unsigned long) since the %d format expects
an integer of some sort.

....which is what it gets.
You should use %p for pointer data.

....which is what he did. You need to read more carefully before you follow
up.

--d.
 

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

Similar Threads


Members online

Forum statistics

Threads
474,077
Messages
2,570,566
Members
47,202
Latest member
misc.

Latest Threads

Top