What exactly is a const expression?

This is a discussion on What exactly is a const expression? within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by Elysia A function return is NOT considered a constant expression (although the next standard will add a ...

  1. #16

    Join Date
    Apr 2008
    Quote Originally Posted by Elysia View Post
    A function return is NOT considered a constant expression (although the next standard will add a feature that allows a return from a function to be interpreted as a constant expression).
    Yes, that is what I was trying to say.
    I guess the decision to call the readonly keyword `const' was misleading in that, from the compiler's perspective, its value will not necessarily be known at compile-time.

    Because it's more of a compiler-technical detail, a lot of programmers (myself included) are caught by surprise when their compiler gets angry about using a const, but not const expression, variable in a situation where a const expression is required.
    Last edited by rudyman; 07-14-2008 at 01:21 PM.

  2. #17
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Indeed. I agree it's misleading.
    And I also think that some things should be enhanced to allow for more constant expressions.
    Such as float, double, const char* in templates (at least the former), constant expression functions. That would be nice. Among other things.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.
    For information on how to enable C++11 on your compiler, look here.
    よく聞くがいい!私は天才だからね! ^_^

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Drawing Program
    By Max_Payne in forum C++ Programming
    Replies: 21
    Last Post: 12-21-2007, 04:34 PM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 12:26 AM
  5. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21