4D SYSTEMS FORUM

Register New Posts
 
 
 


Reply
 
Author Comment
 
pgerlach

Registered: 26/05/12
Posts: 19
Reply with quote #1 
Hello,

I have a question regarding variable initialization. In this sample

Code:
var val := 3;var v1 := 50 + val * 12;var v2;v2 := 50 + val * 12;

it appears that v1 is 50, whereas v2 is 86. If I replace "val" by its numeric value in init, doing

Code:
var v1 := 50 + 3 * 12;var v2;v2 := 50 + 3 * 12;

both v1 and v2 are equal to 86.

I could understand that v1 and v2 being initialized this way would mean their value is pre-calculated by the compiler during compile time, so that when they are initialized the memory is directly set to the good value. Thus, val being unavailable at compile time, it would be ignored in the first example. Even though it seems weird to me, why not. But what I don't understand is why I get no warning at all from the compiler...

A simple sample is attached.

 
Attached Files:
4dg var_init.4dg (227 Bytes, 4 views)

__________________
pierre

meldavia

Registered: 18/03/07
Posts: 900
Reply with quote #2 
Yes you are correct , the initializer values are calculated by the preprocessor, and will not take into consideration
the value of any variables at this time, in its wisdom it actually uses the offset of the variable in the computation
which is of course not what we want.

Then the compiler quite happily takes over after preprocessing,  and does not produce code as expected.

If you put a few more dummy vars in front of your test code, you will see that the value will change accordingly.

This has been noted, and will be addressed in the next compiler update.


__________________
Regards,
Dave
Previous Topic | Next Topic
Print
Reply

Quick Navigation:

Powered by Website Toolbox - Create a Website Forum Hosting, Guestbook Hosting, or Website Chat Room for your website.