|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
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? |
|
#2
|
|||
|
|||
|
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/ |
|
#3
|
|||
|
|||
|
ok, thanks for the reply
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > c - don't understand something in k&r book |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|