Re: Just curiosity about some constructs
- From: gordonb.6f3c6@xxxxxxxxxxx (Gordon Burditt)
- Date: Tue, 31 Jan 2006 17:13:54 -0000
>I have still curiosity about the reason of some C constructs/keywords...
>
>The first is about static functions. What was the reason of restricting
>a function to be visible just in a specific source file? Wasn't it
>sufficient not to be given a prototype (for visibility)?
No. The names would still conflict at link time.
And early C had no prototypes, per se, although there were
declarations which declared the return type (but not argument types).
>What about register and volatile variables? Was at that time a compiler
>not smart enough to optimize with in-register variables?
Yes, and sometimes people wanted to give the compiler hints
that the default optimization wasn't doing the best it could.
>And why would
>someone suggest the compiler not to optimze by making a variable
>volatile?
Because the variable can be changed by *SOMETHING ELSE*. Either
the variable isn't memory but a hardware register, or it's modified
by a signal handler, another thread, etc.
while (siop->statusregister & TX_BUFFER_EMPTY)
/* wait */ ;
The classic problem comes when the compiler loads the value once,
then goes into an infinite loop rather than checking when the flag
comes on repeatedly.
>Last question! This is about the switch statement. The statement seems
>to me to be completely different from others. Let me explain with an
>example. A while(condition) will execute the statement after the
>while(), and if someone wants to have more instructions to be executed
>in the loop, then { } should be used. This is true also for if/else,
>do/loop, but not with the switch. A case does not require any { } to
>execute more than one instruction, moreover, a brake must be given to
>make a single case being executed, otherwise all the following
>non-brake case statements will be executed. Why wasn't the switch like
>the others with { } and automatic brake?
The switch *DOES* use { }, but it's very, very, very rarely appropriate
to use switch without { }.
You can do the same thing within { } (anywhere, as in after a while)
with labels and goto (although case labels are a little different
from regular labels, they are still labels).
Gordon L. Burditt
.
- References:
- Just curiosity about some constructs
- From: Sensei
- Just curiosity about some constructs
- Prev by Date: Re: Just curiosity about some constructs
- Next by Date: Re: Question about the clc string lib
- Previous by thread: Re: Just curiosity about some constructs
- Next by thread: Find the Data Type of Variable
- Index(es):
Relevant Pages
|