K&R Ex 1-3

B

Bill Buckels

Turn up your warning levels then.

But GCC already does provide a very interesting warning which to me is
irrelevant:

C:\gcc>gcc test.c -o test.exe
test.c:7:2: warning: no newline at end of file

C:\gcc>test
foo

here's the code:

#include <stdio.h>

main()
{
puts("foo");
return 0;
}

Note: do not press enter above.

Microsoft C has no problems with any of that:

C:\gcc>cl test.c
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

test.c
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
test.obj

C:\gcc>test
foo

Until we turne-up the Warning Level

C:\gcc>cl test.c -W4
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 14.00.50727.42
for 80x86
Copyright (C) Microsoft Corporation. All rights reserved.

test.c
test.c(4) : warning C4431: missing type specifier - int assumed. Note:
C no longer supports default-int
Microsoft (R) Incremental Linker Version 8.00.50727.42
Copyright (C) Microsoft Corporation. All rights reserved.

/out:test.exe
test.obj

However even --help using gcc failed to reveal how to set a higher
warning level and either one shoudl assume that gcc does not support
warning levels or considers these to be irrelevant and newlines at the
end of a file to be relevant.

Microsoft C has no problem providing information on how to use warning
levels with their compiler from the command line.

I believe that a comment was made here about trying to find someone a
better compiler. Suggest you all might want to try Microsoft C for a
better compiler:)

Regards,

Bill Buckels
 
B

Bill Buckels

I believe that a comment was made here about trying to find someone a
better compiler. Suggest you all might want to try Microsoft C for a
better compiler:)

Actually it was "more decent" compiler but IMNSHO the OP meant
"better"!
 
B

Bill Buckels

2 years ago, I stopped using any products from Microsoft and from that
time my general idea about both computers and programming have gone wider
and better and of good amount of depth.  

Of course my Dear Fellow, I feel the enlightenment shining from my CRT
but we used to call that "irradiation". I have only been using gcc for
over 10 years and have been programming in C for almost 30 years so my
perspective is obviously not as valid. I have about 100 C compilers
installed on this toy box at home, so I can see how shallow my depth
has grown. You make a good point.

And when groups of these individuals who have transcended gather
together it is always fine to say that compiler X is better than MSC
or compiler Y is better than Aztec C but never the other way around.

Regards,

Bill Buckels
 
A

arnuld

But GCC already does provide a very interesting warning which to me is
irrelevant:

C:\gcc>gcc test.c -o test.exe
test.c:7:2: warning: no newline at end of file

where are the warning flags ?

gcc -std=x -pedantic -Wall -Wextra file.c

x = c89 or c99


here's the code:

#include <stdio.h>

main()
{
puts("foo");
return 0;
}

[arnuld@raj C]$ gcc -ansi -pedantic -Wall -Wextra test.c
test.c:7: warning: return type defaults to `int'

thats a good warning I think, and YES, I followed your next instruction:

"Note: do not press enter above"



Microsoft C has no problems with any of that:

2 years ago, I stopped using any products from Microsoft and from that
time my general idea about both computers and programming have gone wider
and better and of good amount of depth.
 
B

Bartc

Richard Heathfield said:
Bill Buckels said:

Try these to be going on with...

-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 -ffloat-store -fno-builtin -O2

OK, but how do you get gcc to tell you all these things? Gcc is either very
unfriendly or assumes everyone knows this stuff. Or perhaps it's buried in
the 11000 lines of man info I once saw (I now use gcc/mingw so no man
command).

Sometimes there is an advantage to using a simple compiler like, say,
lccwin32.

"C:\c>gcc --help
....
-Wa,<options> Pass comma-separated <options> on to the
assembler
-Wp,<options> Pass comma-separated <options> on to the
preprocessor
-Wl,<options> Pass comma-separated <options> on to the linker
....
Options starting with -g, -f, -m, -O, -W, or --param are automatically
passed on to the various sub-processes invoked by gcc. In order to pass
other options on to these processes the -W<letter> options must be used."

???
 
S

santosh

Bartc said:
OK, but how do you get gcc to tell you all these things?

info gcc if you have installed it's documentation, which is almost
always true.

Otherwise you can download the complete documentation for your version
from the GNU GCC website in multiple formats like HTML or PDF.

Gcc is either
very unfriendly or assumes everyone knows this stuff.

It's one of the most intuitive compilers I have worked with.
Or perhaps it's
buried in the 11000 lines of man info I once saw (I now use gcc/mingw
so no man command).

Cygwin might be a fuller UNIX environment.
Sometimes there is an advantage to using a simple compiler like, say,
lccwin32.

Not in this case though. The main advantage of lcc-win32 is ease of
download and installation and the fact that it includes things like
IDE, debugger etc.
 
R

Richard

Bartc said:
OK, but how do you get gcc to tell you all these things? Gcc is either very
unfriendly or assumes everyone knows this stuff. Or perhaps it's buried in
the 11000 lines of man info I once saw (I now use gcc/mingw so no man
command).

Or perhaps its just a question for typing

"gcc --help" and reading what it says?

From there we get

gcc -v --help

Although google is your friend too and the heaps of detailed help out
there on the web.


With power comes responsibility :-;
 
A

arnuld

Of course my Dear Fellow, I feel the enlightenment shining from my CRT
but we used to call that "irradiation". I have only been using gcc for
over 10 years and have been programming in C for almost 30 years so my
perspective is obviously not as valid. I have about 100 C compilers
installed on this toy box at home

:-O

And when groups of these individuals who have transcended gather
together it is always fine to say that compiler X is better than MSC
or compiler Y is better than Aztec C but never the other way around.


I am sure I can't follow you here but that is quite OT discussion. So I
simply stop here.
 
B

Bartc

[Getting gcc to show warning options]

santosh said:
info gcc if you have installed it's documentation, which is almost
always true.

I assumed that this 50MB download would include basic docs! No info command
but I did find gcc.info which explained the options.

Richard said:
Or perhaps its just a question for typing
"gcc --help" and reading what it says?

OK, after (the first time) trying the options -h, --h, -help,
finally --help, it shows:

" --target-help Display target specific command line options
(Use '-v --help' to display command line options of sub-processes)"

Nothing to indicate this will be very useful, but even if I try -v --help, I
get 1000 or 2000 lines of information, which mentions -Wall for example but
doesn't explain it.

Richard Heathfield said:

Not on my version (this is on Windows).

So I still maintain the compiler is not very helpful.

Such basic information should be readily available without needing to look
elsewhere, or wading through tons of docs.
 
R

Richard

Bartc said:
[Getting gcc to show warning options]

santosh said:
info gcc if you have installed it's documentation, which is almost
always true.

I assumed that this 50MB download would include basic docs! No info command
but I did find gcc.info which explained the options.

Richard said:
Or perhaps its just a question for typing
"gcc --help" and reading what it says?

OK, after (the first time) trying the options -h, --h, -help,
finally --help, it shows:

" --target-help Display target specific command line options
(Use '-v --help' to display command line options of sub-processes)"

Nothing to indicate this will be very useful, but even if I try -v --help, I
get 1000 or 2000 lines of information, which mentions -Wall for example but
doesn't explain it.

Then you need to refer to the manual. It's not going to hold your hand
:-; GCC is a powerful program - you need to respect that.

Good luck!
 
S

santosh

Bartc said:
[Getting gcc to show warning options]

santosh said:
info gcc if you have installed it's documentation, which is almost
always true.

I assumed that this 50MB download would include basic docs! No info
command but I did find gcc.info which explained the options.

Hmm. It's some time since I was involved with Windows so I do not
remember what exactly MinGW included by the way of documentation. I do
know that DJGPP includes the full set of documentation (if you opt to
select it during download) along with the 'man' and 'info' commands to
read them. Cygwin also has just about everything that you would expect
to find with a UNIX gcc installation. As a last resort you'll have to
download gcc's manuals available at the site I included a link to in my
previous post.

If I recall correctly, MinGW includes it's own implementation of the
standard library which presumably includes the documentation too.
Otherwise the Dinkumware site is a great resource for this.
Not on my version (this is on Windows).

So I still maintain the compiler is not very helpful.

Such basic information should be readily available without needing to
look elsewhere, or wading through tons of docs.

Note that the GCC project is quite separate from the MinGW project. It's
rather uncharitable to blame the former for the deficiencies of the
latter. Similarly DJGPP and Cygwin are also not connected with the GNU
GCC project except for the fact of a shared code base.
 
U

user923005

Not on my version (this is on Windows).

So I still maintain the compiler is not very helpful.

Such basic information should be readily available without needing to look
elsewhere, or wading through tons of docs.

Try:
info gcc
 
A

arnuld

Such basic information should be readily available without needing to
look elsewhere, or wading through tons of docs.


you have to. Every piece of software is its creator's vision. Some
visions are good and some are literally much worse misfortunes of
human history. Regarding GCC, I think -Wall and -Wextra will be enough
unless you have some very-specific requirements, in this case you have to
dig the documentation or better search the GCC mailing lists first for if
someone already posted about the same requirements as yours.

In the end, RMS is one of best Hackers you will ever come across in your
lifetime.
 

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
473,778
Messages
2,569,605
Members
45,238
Latest member
Top CryptoPodcasts

Latest Threads

Top