We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, I have a problem with the uVision IDE for programming Atmel ARM-based microcontrollers. This is the code:
main() { int *pa; pa = 0x200000; *pa = 0xFFFF; }
Very simple... On Windows C compiler this code will not be any problem, apart from the fact that application will crash because the memory location specified is not accessible. On uVision, instead, the compiler reports this error message:
main.c(6): error: #513: a value of type "int" cannot be assigned to an entity of type "int *"
Thank you in advance, Luca
I seriously doubt that a Windows C compiler will not spit out an error. You must use a typecast here:
pa = (int*)0x200000;
Thank you very much!!!! I could not find it anywhere!
I used Dev-C++ and it didn't report me any error while were compiling...
Well, you would have found it in a good book on C. You can ignore me, I'm just being pedantic :-)
Dev-C++ is an IDE solution.
But gcc, that is the actual compiler, is good at complaining. Especially if using -Wall to turn all full set of warnings. But gcc also supports a number of new and old language standards, which will change what it consider proper.
I seriously doubt that a Windows C compiler will not spit out an error.
A somewhat typical C compiler would not treat this as an error --- but most would be prepared to issue a warning.
A C++ compiler, OTOH, must treat this as an error, because the language definition says so.
Lesson to be taken home from this exercise: many books, and even more people claim that C were just a simple sub-set of C++. They're all wrong.
Thank you all for the clarifications!!! I've a book on C and I realized that the topic "cast" is well covered, but there are not yet arrived, because lho too hasty in wanting to do complicated exercises...
"They're all wrong." No. C _were_ a subset. But isn't anymore.
Really?
C & C++ share a common subset - but I didn't think C++ was ever purely a superset of C ?
Note that C++ existed for many years before the first C++ standard was established. There was a time when Cfront was the way to build C++ applications - a tool specifically converting the C++ extensions into C code.