Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Separate compilation and access to small integer data in other programs

Reply
Thread Tools

Separate compilation and access to small integer data in other programs

 
 
Fred K
Guest
Posts: n/a
 
      11-27-2012
On Monday, November 26, 2012 2:41:42 PM UTC-8, Eric Sosman wrote:
> On 11/26/2012 5:14 PM, Keith Thompson wrote: > Ben Bacarisse <(E-Mail Removed)> writes: > [...] >> One of the most constant things in C is a function. Can you use >> >> int constant_one() { return 42; } >> >> in place of >> >> const int constant_one = 42; >> >> ? Just a thought. >> >> <snip>> > And if you define it as "inline", it probably won't generate any > more code than a const-qualified object declaration (or an enum). The objective (as I understood it) was to make the value accessible to a module that would not require recompilation if the value were to change. There's no theoretical barrier to link-time inlining, but my impression is that it's fairlybleeding-edge stuff. Summing up, the thread has touched on three ways of making the value accessible: 0) #define it, and #include wherever needed. Pro: Simple, potential for constant expression. Con: Must recompile "everything" if value changes. 1) Use a `const'-qualified variable, and #include an `extern' declaration. Pro: Minimizes recompilation. Con: No chance for constant expression, `const' variable may be vulnerable to change at run-time. 2) Use a function returning the value, #include function's declaration. Pro: Minimizes recompilation, makes run-time change very unlikely, allows non-constant initialization. Con: No chance for constant expression.


Why wouldn't this work:

Module A:
----------------
const int ival=42;

int getIval() {return ival;}


Module B:
----------------
#include "ModuleA.h" /* declares getIval() */

void myFunction() {
const int ival = getIval();

}
--
Fred K
 
Reply With Quote
 
 
 
 
Eric Sosman
Guest
Posts: n/a
 
      11-27-2012
On 11/27/2012 2:22 PM, Fred K wrote:
> On Monday, November 26, 2012 2:41:42 PM UTC-8, Eric Sosman wrote:
>> On 11/26/2012 5:14 PM, Keith Thompson wrote: > Ben Bacarisse <(E-Mail Removed)> writes: > [...] >> One of the most constant things in C is a function. Can you use >> >> int constant_one() { return 42; } >> >> in place of >> >> const int constant_one = 42; >> >> ? Just a thought. >> >> <snip> > > And if you define it as "inline", it probably won't generate any > more code than a const-qualified object declaration (or an enum). The objective (as I understood it) was to make the value accessible to a module that would not require recompilation if the value were to change. There's no theoretical barrier to link-time inlining, but my impression is that it's fairly bleeding-edge stuff. Summing up, the thread has touched on three ways of making the value accessible: 0) #define it, and #include wherever needed. Pro: Simple, potential for constant expression. Con: Must recompile "everything" if value changes. 1) Use a `const'-qualified variable, and #include an `extern' declaration. P

ro: Minimizes recompilation. Con: No chance for constant expression, `const' variable may be vulnerable to change at run-time. 2) Use a function returning the value, #include function's declaration. Pro: Minimizes recompilation, makes run-time change very unlikely, allows non-constant initialization. Con: No chance for constant expression.

Nice quoting style ...

> Why wouldn't this work:
>
> Module A:
> ----------------
> const int ival=42;
>
> int getIval() {return ival;}
>
>
> Module B:
> ----------------
> #include "ModuleA.h" /* declares getIval() */
>
> void myFunction() {
> const int ival = getIval();
>
> }


It would work just fine: It's a hybrid of methods (1) and (2),
with all the disadvantages of both in one convenient package. (It
could be made pure (2) by adding a `static' to Module A.)

--
Eric Sosman
http://www.velocityreviews.com/forums/(E-Mail Removed)d
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Diff bw Small integer and Capitol integer vijjirams@gmail.com ASP .Net 0 09-17-2008 02:41 PM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:27 AM
Separate Tabs, Separate Sessions BigAndy Firefox 0 05-09-2007 09:26 AM
Using separate classpaths for separate classes? Frank Fredstone Java 1 06-27-2006 06:46 AM
How to use several separate classes (separate files) to be executed in one class (another file) EvgueniB Java 1 12-15-2003 01:18 AM



Advertisments