how can I get warning ?

D

DaVinci

int main()
{
double d = 33.33;
int i = d;
return 0;
}

Makefile:

gcc -c -g -Wall -std=c99 test.c
but I can't get any warning information.
how can I get the warning on the type converation?
 
T

Tom St Denis

DaVinci said:
int main()
{
double d = 33.33;
int i = d;
return 0;
}

Makefile:

gcc -c -g -Wall -std=c99 test.c
but I can't get any warning information.
how can I get the warning on the type converation?

use a C++ compiler :)

That's not invalid C as far as I can tell. You can add -W [or now
-Wextra] for more warnings though.

Tom
 
T

Tom St Denis

DaVinci said:
what a pit.
I used to waste a long time to debug a programme whose problem is just
there.

Write better code?

If you can't keep track of your variables then choose names that
represent their types, e.g.

int iCounter;
float fTotal;
double dAverage;
char cName[MAXSTR];

etc...

Otherwise, just be more careful and only use the types the problem
requires.

Tom
 
J

Joe Wright

DaVinci said:
int main()
{
double d = 33.33;
int i = d;
return 0;
}

Makefile:

gcc -c -g -Wall -std=c99 test.c
but I can't get any warning information.
how can I get the warning on the type converation?
What warning?

#include <stdio.h>
int main(void)
{
double d = 33.33;
int i = d;
printf("%d\n", i);
return 0;
}

Is perfectly valid C.
 
K

Keith Thompson

Joe Wright said:
What warning?

#include <stdio.h>
int main(void)
{
double d = 33.33;
int i = d;
printf("%d\n", i);
return 0;
}

Is perfectly valid C.

Yes, which is why it would be a warning and not an error message (in a
typical implementation; the standard, of course, makes no such
distinction between different kinds of diagnostic messages).

You might reasonably want a warning on implicit conversions that lose
information, as this one does.

The answer to the original question is: There is no mechanism in
standard C to control which warnings will be issued. Try the gcc
documentation; failing that, try gnu.gcc.help.
 

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

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,190
Latest member
ClayE7480

Latest Threads

Top