User Profile

Collapse

Profile Sidebar

Collapse
pkv314
pkv314
Last Activity: Mar 21 '13, 07:13 AM
Joined: Mar 12 '13
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • Compiler specific



    Thank you. Yes, this is TOTALLY compiler specific. I have compiled this code with icc, g++ (under Unix), and Dev-C++ (under Windows). All of these compilers generate code which prints 3.1415926 (i.e. alias variable and explicit casting do not change the const variable). Compilers create two INDEPENDENT variables pi=3.1415926 and pi_copy=4.0. I was thinking about migration to Dev_C++, but it has some...
    See more | Go to post

    Leave a comment:


  • pkv314
    started a topic const variable in C++ can be changed using aliases
    in C

    const variable in C++ can be changed using aliases

    Hello.
    const qualifier is usually posed as better alternative to #define (because it allows to check types). The simple program shows how const variable can be changed in C++

    Code:
    const double pi = 3.1415926;
    	double& pi_copy = (double&)pi;
    	pi_copy = 4.0;
    	cout << pi << endl;
    Result of printing of pi will be 4. I used Visual C++ 2010 under Windows XP.

    As far...
    See more | Go to post
    Last edited by weaknessforcats; Mar 12 '13, 07:55 PM. Reason: added code tags
No activity results to display
Show More
Working...