C Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesC Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 1st, 2003, 04:42 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
c - don't understand something in k&r book

following c programming by kernighan and ritchie at the moment.

something doesn't add up. contradicts:

(page 40) - talking about variable declerations - "if the variable in question is not automatic, the initialization is done once only, conceptually before the program starts executing, and the initializer must be a constant expression"

then when talking about scope rules (page 80) - "the scope of an external variable or a function lasts from the point at which it is declared to the end of the file being compiled"

this seems to be a contradiction to me. the first part i've quoted gives the impression that variables that are outside any functions (not automatic), an external variable, (regardless of their position in the code) will be available from the start of the code.

where as the other part says that it's available from the point it's initialised downwards - and that's what more of that section round page 80 gives the impresssion of.

if an external variable is initialised some way down the code, then this will not be initialised conceptually before the program starts. i'm guessing the 2nd part is correct?

Reply With Quote
  #2  
Old January 1st, 2003, 07:22 PM
ClayDowling ClayDowling is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Flint, MI
Posts: 328 ClayDowling User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 19 m 25 sec
Reputation Power: 11
Balance,

You're thinking too much about this and confusing yourself.

Your compiler knows about a variable only from the point where it first appears in the source code, which is what the p80 quote is saying. The p40 quote indicates that when the runtime is loaded into memory, part of that runtime may include the initialized value. The mechanism for runtime initialization of variables isn't something you need to worry about - that's a detail for your compiler implementer to sweat.

Really, I wouldn't worry much about it right now. The discussion of variable scope is what you'll need to understand to write your code.
__________________
Clay Dowling
Lazarus Notes
Articles and commentary on web development
http://www.lazarusid.com/notes/

Reply With Quote
  #3  
Old January 1st, 2003, 08:13 PM
balance balance is offline
.
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Posts: 296 balance User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 11
ok, thanks for the reply

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesC Programming > c - don't understand something in k&r book

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap