Jump to content
  • Advertisement

Archived

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

Xanth

Strange Variable Behaviour in Turbo C++ 3

This topic is 5826 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

Hello, I am using Turbo C++ 3 (trying to write a graphics library, mainly for "fun" ), however I'm having trouble with variables, let me show you an example... So, say I want to set a variable to the value 1024*768... If I take the product of that operation and use it, i.e.
long myVar = 786432; // Works fine...  
However, the following does not work...
long myVar = 1024*768; //Can't figure out why this doesn't work... It is always Zero 
Any help would be greatly appreciated. [edited by - Xanth on December 7, 2002 7:49:59 PM]

Share this post


Link to post
Share on other sites
Advertisement
My guess is the asterisk is being interpreted as the indirection symbol instead of the multiplication which you want.

You might try writing it as

long myVar = 1024*+768;

thus telling the parser the 768 is a number, not an address.

Hope this helps.

Stevie.

Share this post


Link to post
Share on other sites
Nope, no good I''m afraid...

It works with small numbers like 5*5, I just don''t get it, what a pain in the butt...

Oh well, I wanted to write the graphics routines (the basic ones, mode setting, pixel plotting, etc...) in Assembly anyway, once they are written I should be able to compile and link with most compilers, I think...

Though, I''d still really like to find a fix for this problem...


Thank you for your help I appreciate your trying.

Share this post


Link to post
Share on other sites
I''m sorry my idea didn''t work.

Have looked at various books re variable initialisation and they seem to indicate no limitation on the assignment expression, beyond having to inform the pre-processor how to cast the result.

OK. So, not having Turbo C++ V3, I can only offer lame suggestions like declaring the numbers as constants. That way, when subsequently used, their size and range is known.

const int screenwidth = 1076;
const int screenheight = 768;

long myVar = screenwidth * screenheight;


Would also suggest a look into the online help under Variable Initialisation. Maybe TC++ has some differences or limitations?

Hope this helps.

Stevie.

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!