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!
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
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
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 ;)
well ANSI C does not need any casting to mallocs
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
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
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
(!) (!)
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 :)
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
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
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
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 ===
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
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)
Quote from: LiK on May 19, 2009, 11:35:44 PM
ok i enabled full-command-line logging but the message is exactly the same as above..
Please post the commandline !!!
Did you see my example above, where it showed the compiler being called? Yours has it also (somewhere). That is the command I need to see.
For the version number ... open the command window, then CD to the directory with the gcc compiler. Then issue the command "gcc -v". I need to know what version of gcc you are using.
Ringo
ok gcc version is 3.4.2 (mingw-special).
ok i see your line. its the build log. Here is mine
[ 50.0%] mingw32-g++.exe -pedantic -Wall -ansi -g -c "C:\...\1.c" -o "C:\...\1.o"
it is using g++ instead of gcc.. why?
In compiler settings mingw32-gcc.exe is selected as default C compiler.
mingw32-g++.exe is selected for C++.
The file is blabla.c and when i create a new one i select C, not C++..
Thx
The g++ compiler of course expects all input files to be be C++ files; I'm not sure how you got to this point.
Go to Settings->Compiler and Debugger and on the "Selected Compiler" list select the compiler you are using (probably called GNU GCC Compiler), then click the tab called "Toolchain executables". There will be both a C compiler and a C++ compiler listed there. Make sure that "mingw32-gcc.exe" is listed for the C compiler.
Ringo
Thing is that i did not change anything there..
yes i already checked there and its mingw32-gcc.exe as C compipler.
But for some reason it uses the mingw32-g++.exe compiler which is the selection for C++.
It will only work if i put mingw32-gcc.exe as C++ compiler(!)
Seems like it cannot see that my file is a C file (despite the fact that its .c)
Quote from: LiK on May 20, 2009, 07:54:01 PM
Seems like it cannot see that my file is a C file (despite the fact that its .c)
Look at the file's (!) properties what compiler environment is selected there. Maybe you changed that by accident.
what do u mean? where do i find this?
file-> properties? (nothing strange there..)
Thank you
Quote from: LiK on May 21, 2009, 02:43:20 PM
what do u mean? where do i find this?
File -> properties -> tab "advanced" -> compiler variable and compiler. Do *not* modify just post what's written there.
erm.... nothing?!!
check the image attached
[attachment deleted by admin]
Quote from: LiK on May 22, 2009, 12:22:01 AM
erm.... nothing?!!
...but you*did* create a project? Or do you try to compile a single file? If so - create a project. ;-)
erm... no i didn't :shock:
i tried with project and the file compiles jsut fine! thank you!
But again.. why it did not compile as a single file? More specifically why it does compile but uses the wrong compiler?
Has to do with the project thing?
ie In ms visual C++ IDE u cannot (i think:P) compile a single file, *but* the compile etc buttons are non-clickable..
Quote from: LiK on May 22, 2009, 06:13:51 PM
why it does compile but uses the wrong compiler?
This is by design. Supporting single-file compilation has limitations (for several good reasons). Actually I would vote to disable it completely to avoid such misunderstandings.
hm.. ok now i understand :)
btw.. better disable it completely or warn that it only compiles C++ single files!
Quote from: BloodyCakeActually I would vote to disable it completely to avoid such misunderstandings.
I would vote to improve it (that's what I use the most of C::B) :D
Quote from: Ceniza on May 31, 2009, 03:46:23 PM
Quote from: BloodyCakeActually I would vote to disable it completely to avoid such misunderstandings.
I would vote to improve it (that's what I use the most of C::B) :D
I would vote to have an option to enable it; that by default is disabled.
Tim S
Quote from: stahta01 on June 01, 2009, 01:16:05 AM
Quote from: Ceniza on May 31, 2009, 03:46:23 PM
Quote from: BloodyCakeActually I would vote to disable it completely to avoid such misunderstandings.
I would vote to improve it (that's what I use the most of C::B) :D
I would vote to have an option to enable it; that by default is disabled.
I change my vote to have an "all-in-one device suitable for every purpose" a.k.a. "Swiss Army knife". I am already developing the coffee maker plugin... stay tuned. :lol: