Compiler flags

S

spasmous

Can someone point me to a website that lists the compiler flags for the
Linux c++ compiler. Yes, I know it's called c++ but I am using it to
compile .c files.
 
J

J. J. Farrell

spasmous said:
Can someone point me to a website that lists the compiler flags for the
Linux c++ compiler. Yes, I know it's called c++ but I am using it to
compile .c files.

There's a chap called Google who can be contacted at
http://www.google.com - he knows all about that sort of thing.
 
R

Richard Heathfield

J. J. Farrell said:
There's a chap called Google who can be contacted at
http://www.google.com - he knows all about that sort of thing.

That's like claiming that Mr Yellow Pages knows all about how to clean
drains, bake bread, drive taxis, and issue passports.

Google is a search engine, not an oracle. It doesn't know anything about
Linux, C++, or compiler flags. In fact, it knows little more than which
words appear on which Web sites. An intelligent Googler is well aware that
there is an awful lot of misinformation on the Web, for which Google cannot
reasonably be held responsible. Caveat surfer.
 
K

Keith Thompson

spasmous said:
Can someone point me to a website that lists the compiler flags for the
Linux c++ compiler. Yes, I know it's called c++ but I am using it to
compile .c files.

<OT>
The usual default compiler on Linux is gcc (it's actually a collection
of compilers for several languages, with a shared backend). There's a
command called "g++" that invokes it as a C compiler. Typically "cc"
and "c++" are installed as aliases for "gcc" and "g++", respectively.

If you want to compile C code, use a C compiler: either "gcc" or "cc",
not "g++", or "c++".

All this is explained in gcc documentation, which you can see by
typing "info gcc" or by doing a Google search for "gcc documentation".
</OT>

If you have any more questions about gcc (that aren't answered by the
documentation), try gnu.gcc.help. If you have questions about Linux,
try one of the many Linux newsgroups, or perhaps comp.unix.programmer.
If you have questions about the C language itself, this is the right
place.
 
J

jacob navia

spasmous a écrit :
Can someone point me to a website that lists the compiler flags for the
Linux c++ compiler. Yes, I know it's called c++ but I am using it to
compile .c files.

You should learn to read the documentation.

Just write:

info gcc
or
man gcc

and the associated documentation will tell you ALL compiler
flags, and what they do.
 
S

spasmous

jacob said:
spasmous a écrit :

You should learn to read the documentation.

Just write:

info gcc
or
man gcc

and the associated documentation will tell you ALL compiler
flags, and what they do.

Thanks - I didn't realize c++ was an alias of gcc. Sometimes, you know,
you have to compile someone else's programs on a platform that you
don't know. man c++ was my first try, then google on Linux c++ compiler
flags. Neither produced anything obviously useful.

Next was look for the group with most hits on my google search and post
there. Which is what I did. Sorry your NG is not pure enough for you
guys - but thank you for your suggestions.
 
A

Andrew Poelstra

spasmous said:
Can someone point me to a website that lists the compiler flags for the
Linux c++ compiler. Yes, I know it's called c++ but I am using it to
compile .c files.

Assuming you mean gcc, the appropriate flags are here (from Richard
Heathfield at some point in the past):
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -O3

Jacob Navia recommends adding -Wextra for the latest version of gcc.

Rather unfortunately, you have to fix the spacing yourself.
 
K

Keith Thompson

Andrew Poelstra said:
Assuming you mean gcc, the appropriate flags are here (from Richard
Heathfield at some point in the past):
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -O3

Jacob Navia recommends adding -Wextra for the latest version of gcc.

Rather unfortunately, you have to fix the spacing yourself.

<OT>
-Wextra is a newer name for -W. "info gcc" for details.
</OT>
 
R

Richard Heathfield

Andrew Poelstra said:
Assuming you mean gcc, the appropriate flags are here (from Richard
Heathfield at some point in the past):
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -O3

No, this set is from "those who know me have no need of my name" - all I did
was pinch it. (And he's been looking for it ever since.)
 
C

CBFalconer

Keith said:
<OT>
-Wextra is a newer name for -W. "info gcc" for details.
</OT>

Here is my set, implemented via an alias:

-W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal -gstabs+ -O1
 
G

Guest

CBFalconer said:
Here is my set, implemented via an alias:

-W -Wall -ansi -pedantic -Wwrite-strings -Wfloat-equal -gstabs+ -O1

I know you're not the first to recommend it, but please keep in mind
that gcc with the -Wwrite-strings option by design does not conform to
any standard. (Without that option, it still has bugs, but at least it
tries to be conforming.)
 
R

Richard Heathfield

Harald van D?k said:
I know you're not the first to recommend it, but please keep in mind
that gcc with the -Wwrite-strings option by design does not conform to
any standard.

Why not? All that -Wwrite-strings does is issue an extra diagnostic message
under certain circumstances, and implementations are allowed to issue
whatever diagnostic messages they like.
 
G

Guest

Richard said:
Harald van D?k said:

Why not? All that -Wwrite-strings does is issue an extra diagnostic message
under certain circumstances, and implementations are allowed to issue
whatever diagnostic messages they like.

Not if they cause a strictly conforming program such as the below to no
longer compile.

int main(void) {
if(0) ++*"";
}
 
R

Richard Heathfield

Harald van D?k said:
Not if they cause a strictly conforming program such as the below to no
longer compile.

int main(void) {
if(0) ++*"";
}

me@here:~/scratch> cat foo.c
int main(void) {
if(0) ++*"";
}

me@here:~/scratch> make
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
foo.c: In function `main':
foo.c:2: warning: increment of read-only location
foo.c:3: warning: control reaches end of non-void function
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -o foo foo.o -lm

See? It still compiles.
 
G

Guest

Richard said:
Harald van D?k said:

me@here:~/scratch> cat foo.c
int main(void) {
if(0) ++*"";
}

me@here:~/scratch> make
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -c -o foo.o foo.c
foo.c: In function `main':
foo.c:2: warning: increment of read-only location
foo.c:3: warning: control reaches end of non-void function
gcc -W -Wall -ansi -pedantic -Wformat-nonliteral -Wcast-align
-Wpointer-arith -Wbad-function-cast -Wmissing-prototypes
-Wstrict-prototypes -Wmissing-declarations -Winline -Wundef
-Wnested-externs -Wcast-qual -Wshadow -Wconversion -Wwrite-strings
-Wno-conversion -ffloat-store -O2 -g -pg -o foo foo.o -lm

See? It still compiles.

Interesting. It doesn't with gcc 3.3.6, 3.4.6, 4.0.3 or 4.1.1.
"increment of read-only location" is an unconditional error in all four
of those versions.
 
S

Spiros Bousbouras

Harald said:
Not if they cause a strictly conforming program such as the below to no
longer compile.

int main(void) {
if(0) ++*"";
}

How can a programme which tries to modify
what might be read-only memory be strictly
conforming ? And what is its return value
supposed to be ?
 
G

Guest

Spiros said:
How can a programme which tries to modify
what might be read-only memory be strictly
conforming ?

It can't. This program never tries to modify read-only memory, though.
That's what the "if(0)" is for.
And what is its return value
supposed to be ?

In C99, not returning anything on the initial call to main() is
equivalent to returning 0.
 
S

Spiros Bousbouras

Harald said:
It can't. This program never tries to modify read-only memory, though.
That's what the "if(0)" is for.

Ok , what about the following programme ?

unsigned int rnd(void) {
/* Function which returns a random value
* Assume it is conforming.
*/
}

unsigned int power(unsigned int a , unsigned int b) {
/* This function returns the value of
* a raised to the power b. Also assume
* that it is conforming.
*/
}

int main (void) {
unsigned int x , y , z , n ;
char c[] = "a" ;

x=rnd() ; y=rnd() ;
z=rnd() ; n=rnd() ;

if (n>2 && power(x,n) + power(y,n) ==
power(z,n)) c[0]++ ;
}

Since we know that Fermat's last theorem
is true is this a conforming programme ?
 
S

Spiros Bousbouras

Spiros said:
Ok , what about the following programme ?

unsigned int rnd(void) {
/* Function which returns a random value
* Assume it is conforming.
* And that it always returns positive values.
*/
}


unsigned int power(unsigned int a , unsigned int b) {
/* This function returns the value of
* a raised to the power b. Also assume
* that it is conforming.
*/
}

int main (void) {
unsigned int x , y , z , n ;
char c[] = "a" ;

x=rnd() ; y=rnd() ;
z=rnd() ; n=rnd() ;

if (n>2 && power(x,n) + power(y,n) ==
power(z,n)) c[0]++ ;
}

Since we know that Fermat's last theorem
is true is this a conforming programme ?
 
G

Guest

Spiros said:
Ok , what about the following programme ?

unsigned int rnd(void) {
/* Function which returns a random value
* Assume it is conforming.
*/
}

unsigned int power(unsigned int a , unsigned int b) {
/* This function returns the value of
* a raised to the power b. Also assume
* that it is conforming.
*/
}

int main (void) {
unsigned int x , y , z , n ;
char c[] = "a" ;

I think you mean
char *c = "a";
since the point is that *c isn't modifiable.
x=rnd() ; y=rnd() ;
z=rnd() ; n=rnd() ;

if (n>2 && power(x,n) + power(y,n) ==
power(z,n)) c[0]++ ;
}

Since we know that Fermat's last theorem
is true is this a conforming programme ?

No, and with the modification given above, not even if the functions
are implemented as your comments suggest. You're not taking into
account the possibility of overflow, nor are you ensuring that x, y and
z can't all be 0 (or other values for which x**n + y**n == z**n is
trivially true). If your if() expression would always evaluate as zero,
the program would be strictly conforming, but if(0) is a much simpler
way to make sure of this.
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top