Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22057

How can I prevent static data type conversion in C++ with gcc?

$
0
0

I am not sure if my question explains my problem correctly, but I made following observations:I have following C++ program, that I compile on Ubuntu 64bit with default options:

g++ test.c

test1.c:

int main() {    double a = 1;}

test2.c:

int main() {    static double a = 1;}

The programs have following memory layout:

$ size test1.out    text    data     bss     dec     hex filename   1443     544       8    1995     7cb a.out$ size test2.out    text    data     bss     dec     hex filename   1415     552       8    1975     7b7 a.out

My assumption for the different layouts is that in the second case the compiler knows that it only needs one bit to display a '1' whereas in the first case the variable could still be assigned to the maximum double value and thus needs more space.Is this assumption correct and if yes can this be prevented with some compiler keywords or other methods (the image is supposed to have the same size in both cases)?


Viewing all articles
Browse latest Browse all 22057

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>