Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ Moderated > Int-cast floati...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 3 Topic 9294 of 10104
Post > Topic >>

Int-cast floating point expressions as constants?

by Joel Yliluoma <bisqwit@[EMAIL PROTECTED] > Feb 19, 2008 at 01:11 AM

I recently ran across this problem... My code looks like this.

     #define SomeFloat 0.5
     static const int SomeIntConst = ((int)(SomeFloat + 0.5));

     template<int V>
     struct SomeStruct
     {
     };

     int main()
     {
         SomeStruct<SomeIntConst> ();
         return 0;
     }

When I compile this with ICC, or GCC, or Microsoft Visual C++,
with default settings, it compiles properly.

Even with GCC -ansi, it compiles properly.
However, when I compile it with GCC's -pedantic option, I get
the following error messages:

tmp.cc:11: error: 'SomeIntConst' cannot appear in a constant-expression
tmp.cc:11: error: template argument 1 is invalid

What is the right behavior in this situation for a compiler to do?

-- 
Joel Yliluoma - http://iki.fi/bisqwit/

      [ See http://www.gotw.ca/resources/clcm.htm
for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
 




 3 Posts in Topic:
Int-cast floating point expressions as constants?
Joel Yliluoma <bisqwit  2008-02-19 01:11:33 
Re: Int-cast floating point expressions as constants?
Francis Glassborow <fr  2008-02-19 04:36:56 
Re: Int-cast floating point expressions as constants?
Alberto Ganesh Barbati &l  2008-02-19 16:46:34 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Wed Oct 15 22:41:41 CDT 2008.