News:

Accounts with zero posts and zero activity during the last months will be deleted periodically to fight SPAM!

Main Menu

C::B compiles in K&R C and not ANSI C...?

Started by LiK, May 19, 2009, 07:13:27 PM

Previous topic - Next topic

LiK

Hello everyone :)

I think that my C::B is compiling in K&R and not in ASNI C..

ie. with this code

#include <stdlib.h>

int main (void) {

    char *pfilename;
    pfilename = malloc( 1 );

return 0;
}


returns
Quoteerror: invalid conversion from `void*' to `char*'

Of course this pfilename = (char*)malloc( 1 ); compiles without errors.. But this is not ANSI C right?


I tried selecting an other compiler from C::B option but not luck.
Even tried the devC++ compiler but nothing..

Any ideas? what is wrong?


Thank you very much!

rcoll

The "flavor" of C being compiled is a function of the compiler, not the IDE.  Depending upon the compiler you choose and the options you select (specific to that compiler) you will get different modes of compiling.  Note that (AFAIK) the Dev-C++ IDE uses only the GCC compiler.

Ringo

LiK

Yes i am aware of that :)

But i have GNU GCC Compiler selected at C::B compiler options and i tried the same flags..

So i guess there is also something else i need to change in the IDE's option.

Thx for the reply

AlexN

Quote from: LiK on May 19, 2009, 07:13:27 PM
Quoteerror: invalid conversion from `void*' to `char*'

Of course this pfilename = (char*)malloc( 1 ); compiles without errors.. But this is not ANSI C right?


Thank you very much!

I my opinion this is behavior is more ANSI C then K&R. ANSI C checks the type, K&R C assigns all to all.  :)

Alex  ;)
best regards
Alex ;)

LiK

well ANSI C does not need any casting to mallocs

rcoll

By default the GCC C-compiler operates in "C99" mode, which does require a cast of one pointer type to another (in this case a "void *" to a "char *").  C99 is neither K&R nor ANSI, but has elements of both.

However, at this point we are no longer talking about C::B, but the multitude of C standards out there.  You could get better help by asking the guys on USENET on the "comp.lang.c" list.

Ringo

LiK

r u sure about this?

Anyway.. Even so the problem still remains..

Not solved even when i put the -ansi flag at the compiler options.

So i still think it has something to do with C::B. I hadn't that problem with DevC++ or Pelles C.


Thanks

rcoll

Actually, I copied your original code into a brand new C::B "console" project, and it compiled and ran just fine.  No problems at all.  Apparentely the GCC optimizer is smart enough to translate a "void *" into a "char *" with no problems.

Are you sure you are compiling a "C" project, and not a "C++" project?  Is your main program named "main.c" or "main.cpp" ?

Ringo

LiK

(!) (!)
Yes i am.. I posted that only this small part for illustration reasons.

the whole program is much bigger with not other errors.. Just 2 errors of this kind..

What is more i reinstalled C::B and same happened.. :(
any ideas?


thx 4 helping :)

rcoll

When I create a default C-language project, the only compiler options I have checked is optimization "O2", and your code snippet compiled good.

What options do you have checked?  Also, what version of GCC are you using?  My system is using GCC 3.4.4

Ringo

LiK

not sure.. in the options its GNU GCC Compiler

i have tried with various flags checked. and i just tried only with checking O2 but no difference

rcoll

Even with -pedantic warnings turned on, I cannot get it to fail:


mingw32-gcc.exe -pedantic -W -Wall -ansi  -O2     -c C:\temp\test1\main.c -o obj\Release\main.o
Process terminated with status 0 (0 minutes, 0 seconds)
0 errors, 0 warnings


Can you show us your full compiler log output?

Ringo

LiK

sure, but its actually just that

\f.c        In function `int main()':
\f.c   6   error: invalid conversion from `void*' to `char*'
             === Build finished: 1 errors, 0 warnings ===

rcoll

Please turn on full-command-line logging (Settings -> Compiler and Debugger -> Other Settings then "Compiler Logging") then try to compile again.  Copy that log output into here, so we can see what all (hidden) settings are being used.

Also, can you open a command window (for example, a DOS window or a MSys xterm) and type "gcc -v" to see what version of GCC you are using.

Ringo

LiK

ok i enabled full-command-line logging but the message is exactly the same as above..

i open a cmd window and type gcc -v but it is not found..(i guess because its not in the windows directory)