PC Review


Reply
 
 
Joe User
Guest
Posts: n/a
 
      13th Dec 2009
If I declare "Const foo as Integer = 123", does that allocate storage?

Or does that create a compile-time constant that replaces "foo" wherever it
is used in executable statements?

If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
efficient than "x = 123*456"? In particular, does the compiler treat "x =
foo" as "x = 56088"?

 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      13th Dec 2009
The answer to the first question is yes.



"Joe User" <joeu2004> wrote in message
news:(E-Mail Removed)...
> If I declare "Const foo as Integer = 123", does that allocate storage?
>
> Or does that create a compile-time constant that replaces "foo" wherever
> it is used in executable statements?
>
> If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
> efficient than "x = 123*456"? In particular, does the compiler treat "x =
> foo" as "x = 56088"?



 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      13th Dec 2009

I believe that the compiler evaluates any constants and replaces them
with their values before any code execution takes place. This is why
you can assign to constants values that can be evaluated
arithmetically with actual constants (Const ABC = 1234 * 10) or other,
previously declared constants (Const ABC = DEF * 10, where DEF is a
previously declared constant).

As far as efficiency at run time, a simple constant makes no
difference at all and an arithmetic const is only marginally
(microseconds) better than having the arithmetic in the actual run
time code.

Cordially,
Chip Pearson
Microsoft MVP 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com
[email on web site]


On Sat, 12 Dec 2009 16:58:08 -0800, "Joe User" <joeu2004> wrote:

>If I declare "Const foo as Integer = 123", does that allocate storage?
>
>Or does that create a compile-time constant that replaces "foo" wherever it
>is used in executable statements?
>
>If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
>efficient than "x = 123*456"? In particular, does the compiler treat "x =
>foo" as "x = 56088"?

 
Reply With Quote
 
Joe User
Guest
Posts: n/a
 
      13th Dec 2009
"Chip Pearson" <(E-Mail Removed)> wrote:
> I believe that the compiler evaluates any constants
> and replaces them with their values before any code
> execution takes place. This is why you can assign to
> constants values that can be evaluated arithmetically
> with [...] previously declared constants (Const ABC = DEF * 10


Good point! Shoulda thought of that myself. Thanks.


----- original message -----

"Chip Pearson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> I believe that the compiler evaluates any constants and replaces them
> with their values before any code execution takes place. This is why
> you can assign to constants values that can be evaluated
> arithmetically with actual constants (Const ABC = 1234 * 10) or other,
> previously declared constants (Const ABC = DEF * 10, where DEF is a
> previously declared constant).
>
> As far as efficiency at run time, a simple constant makes no
> difference at all and an arithmetic const is only marginally
> (microseconds) better than having the arithmetic in the actual run
> time code.
>
> Cordially,
> Chip Pearson
> Microsoft MVP 1998 - 2010
> Pearson Software Consulting, LLC
> www.cpearson.com
> [email on web site]
>
>
> On Sat, 12 Dec 2009 16:58:08 -0800, "Joe User" <joeu2004> wrote:
>
>>If I declare "Const foo as Integer = 123", does that allocate storage?
>>
>>Or does that create a compile-time constant that replaces "foo" wherever
>>it
>>is used in executable statements?
>>
>>If the latter, is "Const foo as Integer = 123*456" and "x = foo" more
>>efficient than "x = 123*456"? In particular, does the compiler treat "x =
>>foo" as "x = 56088"?


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get Const. Name =?Utf-8?B?QW1qYWQ=?= Microsoft VB .NET 2 13th Jan 2006 07:53 PM
const Jeff Louie Microsoft C# .NET 1 16th Nov 2005 08:22 AM
Casting from non-const to const (C2440) RalphTheExpert Microsoft VC .NET 1 14th Nov 2005 07:48 PM
friend CStringT operator+(const CStringT& str1, const CStringT& st =?Utf-8?B?VG9ueU0=?= Microsoft VC .NET 2 3rd Nov 2004 01:09 PM
Re: crash changing const to public const BrianB Microsoft Excel Programming 0 4th Aug 2003 10:13 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:39 AM.