User forums > Using Code::Blocks

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

(1/7) > >>

LiK:
Hello everyone :)

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

ie. with this code

--- Code: ---#include <stdlib.h>

int main (void) {

    char *pfilename;
    pfilename = malloc( 1 );

return 0;
}
--- End code ---

returns
--- Quote ---error: invalid conversion from `void*' to `char*'
--- End quote ---

Of course this
--- Code: ---pfilename = (char*)malloc( 1 );
--- End code ---
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 ---
--- Quote ---error: invalid conversion from `void*' to `char*'
--- End quote ---

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


Thank you very much!

--- End quote ---

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  ;)

LiK:
well ANSI C does not need any casting to mallocs

Navigation

[0] Message Index

[#] Next page

Go to full version