Archived

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

Strange Variable Behaviour in Turbo C++ 3

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

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 on other sites
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 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...

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.

1. 1
2. 2
3. 3
4. 4
frob
13
5. 5

• 16
• 13
• 20
• 12
• 19
• Forum Statistics

• Total Topics
632170
• Total Posts
3004550

×