www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - How about "inline" for manifest constants?

reply Russell Lewis <webmaster villagersonline.com> writes:
inline int x = 3;

Where the "inline" keyword means "the compiler is free to not allocate 
any storage for this constant."  In particular, this means that it would 
be a syntax error to either:
	1) Take the address of an inline constant
	2) Change its value

Whether or not the compiler actually inlines all instances or not is 
implementation-specific.
Dec 09 2007
next sibling parent "Craig Black" <craigblack2 cox.net> writes:
"Russell Lewis" <webmaster villagersonline.com> wrote in message 
news:fjill0$2jnc$1 digitalmars.com...
 inline int x = 3;

 Where the "inline" keyword means "the compiler is free to not allocate any 
 storage for this constant."  In particular, this means that it would be a 
 syntax error to either:
 1) Take the address of an inline constant
 2) Change its value

 Whether or not the compiler actually inlines all instances or not is 
 implementation-specific.

I like it.
Dec 09 2007
prev sibling parent reply Robert Fraser <fraserofthenight gmail.com> writes:
Russell Lewis wrote:
 inline int x = 3;
 
 Where the "inline" keyword means "the compiler is free to not allocate 
 any storage for this constant."  In particular, this means that it would 
 be a syntax error to either:
     1) Take the address of an inline constant
     2) Change its value
 
 Whether or not the compiler actually inlines all instances or not is 
 implementation-specific.

You mean semantic error? But now we're just talking semantics... Anyways, it's a good idea.
Dec 09 2007
parent reply "Janice Caron" <caron800 googlemail.com> writes:
On Dec 10, 2007 7:18 AM, Robert Fraser <fraserofthenight gmail.com> wrote:
 Anyways, it's a good idea.

Isn't this exactly the same idea as enum int x = 3; but with "inline" instead of "enum"? Aren't we done arguing over what the word should be? I think we should just go with Craig's wildebeest idea! :-)
Dec 10 2007
next sibling parent Bill Baxter <dnewsgroup billbaxter.com> writes:
Janice Caron wrote:
 On Dec 10, 2007 7:18 AM, Robert Fraser <fraserofthenight gmail.com> wrote:
 Anyways, it's a good idea.

Isn't this exactly the same idea as enum int x = 3; but with "inline" instead of "enum"? Aren't we done arguing over what the word should be?

The idea is: if we're going to change the meaning of enum completely why not just replace it with a different word that describes the entirety of it's new job and phase out the word "enum". That way there's no net increase in keywords but we get a more descriptive language.
 I think we should just go with Craig's wildebeest idea! :-)

I think inline is a pretty good suggestion. And inline(enum) could be used to trigger enumeration behavior. But it'll never happen. --bb
Dec 10 2007
prev sibling parent Robert Fraser <fraserofthenight gmail.com> writes:
Janice Caron wrote:
 On Dec 10, 2007 7:18 AM, Robert Fraser <fraserofthenight gmail.com> wrote:
 Anyways, it's a good idea.

Isn't this exactly the same idea as enum int x = 3; but with "inline" instead of "enum"? Aren't we done arguing over what the word should be?

No it's not. With inline or wildbeast, you can create blocks: wildbeast { int mufasa = 99999999999999L; string aslan = "i can has cheezburger?"; } This can't be done with enum. SOme other word besides enum, final or alias needs to be found, IMO, since enum can't create blocks, and final used on blocks would have different meanings for vars and member functions.
Dec 10 2007