Author Topic: Compiler Q's  (Read 11482 times)

Offline vserghi

  • Multiple posting newcomer
  • *
  • Posts: 13
Compiler Q's
« on: August 04, 2005, 01:47:11 pm »
I have just had a quick look at another free IDE called Pelles C (http://www.smorgasbordet.com/pellesc/index.htm), It had a couple of interesting errors that came up whilst trying to compile an existing project. Two things;

1. It told me "Missing prototype for 'printf". Being a complete newbie, I had obviously not included the correct header file. Easy to fix.

2. It managed to tell me that some variables that I had defined were not being referenced. Again easy to fix.

How did C::B (and DevCpp) compile my program with these errors present? How did my program work ok with these errors present (using just plain ol' C)? Is there an option that I can set for me to check for these type of errors? (it uses LCC as its compiler)

As an aside, it had a nice resource editorĀ  :). You can add icons, cursors, menu/table entries, version numbers, manifest info, dialogue info.

Vasilis.

Offline tiwag

  • Developer
  • Lives here!
  • *****
  • Posts: 1196
  • sailing away ...
    • tiwag.cb
Re: Compiler Q's
« Reply #1 on: August 04, 2005, 02:10:39 pm »
I have just had a quick look at another free IDE called Pelles C (http://www.smorgasbordet.com/pellesc/index.htm), It had a couple of interesting errors that came up whilst trying to compile an existing project. Two things;

1. It told me "Missing prototype for 'printf". Being a complete newbie, I had obviously not included the correct header file. Easy to fix.

2. It managed to tell me that some variables that I had defined were not being referenced. Again easy to fix.

How did C::B (and DevCpp) compile my program with these errors present?

different compilers behave different, that's what we have to live with -
- sometimes it's difficult to differentiate between erros and warnings...

How did my program work ok with these errors present (using just plain ol' C)? Is there an option that I can set for me to check for these type of errors?

what you describe can also let be warned by gcc, when you use the compiler switch "-Wall"
or in codeblocks set "Enable all compiler warnings" in Project->Build options->Compiler Flags


about PellesC
(it uses LCC as its compiler)
As an aside, it had a nice resource editorĀ  :). You can add icons, cursors, menu/table entries, version numbers, manifest info, dialogue info.

PellesC is really a very nice piece of SW and very very well thought out and usable.
But limited to C - well for most things but not for all.
And it doesn't use LCC as its compiler, Pelles C-compiler is based on LCC, but it's completely overworked now and targets only Win32.

I have done a lot of small projects with PellesC and i use it regularly when i need some quick tools - mostly console applications.
The IDE with included resource editor and debugger is really delicate - for small projects.

Offline vserghi

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Compiler Q's
« Reply #2 on: August 04, 2005, 02:22:04 pm »
Thanks for that. I will try the "Enable all compiler warnings" option in the compiler and see what I get.

As I have only ever done simple console type programs, I will probably use Pelles C and C::B for my debugging and Pelles C for my resource editing.

I've just tried the option and it did throw up those errors after I put them back in again, nice. Unfortunately it also threw up some more errors. At least I will learn a few things in trying to fix them.

Ta, Vasilis.

Offline kagerato

  • Multiple posting newcomer
  • *
  • Posts: 56
    • kagerato.net
Re: Compiler Q's
« Reply #3 on: August 04, 2005, 05:32:51 pm »
Unfortunately it also threw up some more errors. At least I will learn a few things in trying to fix them.

Warnings and errors tend to cascade with C/C++.  One problem will lead to an error in parsing, but the compiler continues onward and marks additional "errors" that are also the result of the same original problem.

A single missing character can sometimes get you a page-full of "problems".

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Compiler Q's
« Reply #4 on: August 06, 2005, 02:54:00 pm »
1. It told me "Missing prototype for 'printf"  [...]

2. It managed to tell me that some variables that I had defined were not being referenced.

How did C::B (and DevCpp) compile my program with these errors present? How did my program work ok with these errors present (using just plain ol' C)?

1. gcc has a large number of "builtin functions". Among these are many standard math functions, and, too, printf() : http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Other-Builtins.html#Other-Builtins
The good thing about builtins is that some of them (math functions, memcpy, vector funcs etc.) can be optimized to one CPU instruction under optimal circumstances instead of a quite expensive library call. The bad thing is, as you did experience, it will compile certain examples just fine, while other compilers will choke on it. That is not helpful in writing portable programs, admitted.

2. This is not an error. It is not good, but it is not an error. If you call gcc with warnings enabled, it will tell you, but either way, this is nothing that prevents your program from running.
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

grv575

  • Guest
Re: Compiler Q's
« Reply #5 on: August 08, 2005, 07:28:27 am »
Whether printf() is a builtin or not, it still requires the prototype: #include <stdio.h> is needed or I get an error on mingw.

Offline vserghi

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Compiler Q's
« Reply #6 on: August 08, 2005, 10:33:35 am »
I've been to the GNU GCC web site and had a look at the compiler options.

It is not immediatley obvious, which switches are being set when I place a check marks against some of the compiler options in C::B? I seem to remember another thread discussing something about giving users a description of what the options do, or maybe even what switch is being used for that compiler option.

Will this be a feature at somepoint?

Vasilis.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Compiler Q's
« Reply #7 on: August 08, 2005, 01:36:43 pm »
Whether printf() is a builtin or not, it still requires the prototype: #include <stdio.h> is needed or I get an error on mingw.

Really? :)

Code
D:\desktop>echo main(){printf("blah");} > test.c

D:\desktop>gcc test.c -o test.exe

D:\desktop>test.exe
blah
D:\desktop>
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline Urxae

  • Regular
  • ***
  • Posts: 376
Re: Compiler Q's
« Reply #8 on: August 08, 2005, 02:28:36 pm »
You're both right, sort of:
Code
D:\Temp> echo main(){printf("blah");} > test.c

D:\Temp> gcc -o test.exe test.c

D:\Temp> test
blah
D:\Temp> echo main(){printf("blah");} > test.cpp

D:\Temp> g++ -o test2.exe test.cpp
test.cpp: In function `int main()':
test.cpp:1: error: `printf' undeclared (first use this function)
test.cpp:1: error: (Each undeclared identifier is reported only once for each function it appears in.)

D:\Temp>
So it'll work in C, but not in C++. C++ always requires prototypes/definitions, C just assumes that the parameter types are the types of what was passed and that it returns int if no prototype/definition is given (though GCC will warn about it if -Wall is passed).
However, since this thread was about C (Pelles C doesn't support C++) thomas is more right.
This is one of the things I dislike most about C.

-Wall, never compile C without it ;).