pointer casting in visual c

Started by
3 comments, last by kindfluffysteve 21 years, 2 months ago
is it possible in visual c to make it unessary to have to this: char *stuff; stuff=(char *)malloc(100); i hate typing. why cant it be, stuff=malloc(100); ?? can it be, is there setting burried somewhere to change? I''m pretty sure other compilers are more relaxed about this.
Advertisement
Are you actually programming C? I have done very little programming in C, and so I know neither what its casting rules are, nor what Visual C++ is like for this. Visual C++ will presumably use C++ by default, and in C++, which is fairly strongly typed (a controversial statement, I suppose, but I regard C++ as strongly typed with loopholes rather than weakly typed in general), you cannot implicitly cast a void* to anything at all. But then, if you were using C++, you should/would most likely be using operator new ...

As for other compilers being ''more relaxed'', that''s not necessarily a good thing. Relaxed type rules can be very, very dangerous.
first there is no visual c (except its very old and i never heard of it). if you mean visual c++ its an ide and NO language.
malloc is declared as void* malloc(int size) or something, so i seriously doubt that other compilers will ignore those 700 something pages about how c++ is meant to work.

and what about int* bla=malloc(200) ? having to use the cast is a good way to remind the programmer he''s allocating 200 byte and not memory for 200 ints. if you hate typing that much you should actually use c++ stuff and not c. char* stuff=new char[100] should be short enough (and even here you have to specify what that returned pointer is supposed to point at).
f@dzhttp://festini.device-zero.de
stuff = malloc(bytes) is perfectly ok to use - google the comp.lang.c newsgroup for details.


"It is always a simple matter to drag the people along, whether it is a democracy, or a fascist dictatorship, or a parliament, or a communist dictatorship. Voice or no voice, the people can always be brought to the bidding of their leaders. That is easy. All you have to tell them is that they are being attacked and denounce the peacemakers for lack of patriotism and exposing the country to danger. It works the same in any country."
Hermann Goering
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
char *stuff;
stuff = new char[100];

This topic is closed to new replies.

Advertisement