Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

kindfluffysteve

pointer casting in visual c

This topic is 5762 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!