[comp.lang.c] A few random type questions.

mills@baloo.eng.ohio-state.edu (Christopher Mills) (08/27/88)

#undef LINEEATER

My appologies for being in such a curious mode today...

OK.  Let me see if I've got this straight.  There are defaults for both
the storage class and type of an identifier, so if I say

	foo;

outside of a block, I'll get a static int foo, right?  OK, so what if I
write

	bar() { foo; }

obviously, the compiler can't determine if I mean auto int foo, or compute
the expression foo (I assume it assumes the latter).  This is an ambiguity
in the grammar, yes?

Also, is there any real reason for the 'auto' keyword?  Has anyone ever
used it for anything?

Last question: is 'register int baz()' legal and if so would it make any
difference anywhere.

Well, OK, one more.  What (if ever) was 'entry' used for?

				Thanks...
-=-
_________________________________________________________________________
| Christopher Mills              | "If you see someone without a smile, |
| mills@baloo.eng.ohio-state.edu |  give them mine - I'm not using it." |
====== My thoughts are not my own--I'm posessed by mailer daemons. ======

henry@utzoo.uucp (Henry Spencer) (08/28/88)

In article <530@accelerator.eng.ohio-state.edu> mills@baloo.eng.ohio-state.edu (Christopher Mills) writes:
>OK.  Let me see if I've got this straight.  There are defaults for both
>the storage class and type of an identifier, so if I say
>
>	foo;
>
>outside of a block, I'll get a static int foo, right?

Actually, in an X3J11-conforming compiler, you get an error message.
You can't default both type and storage class in X3J11 C.

>Also, is there any real reason for the 'auto' keyword?  Has anyone ever
>used it for anything?

It's not useful, but there is probably old code somewhere that declares
some local int variables with "auto i;" instead of "int i;".  Sigh.

>Last question: is 'register int baz()' legal and if so would it make any
>difference anywhere.

It is explicitly illegal in X3J11 C.

>Well, OK, one more.  What (if ever) was 'entry' used for?

Nothing.  It's no longer part of the language.
-- 
Intel CPUs are not defective,  |     Henry Spencer at U of Toronto Zoology
they just act that way.        | uunet!attcan!utzoo!henry henry@zoo.toronto.edu

gwyn@smoke.ARPA (Doug Gwyn ) (08/28/88)

In article <530@accelerator.eng.ohio-state.edu> mills@baloo.eng.ohio-state.edu (Christopher Mills) writes:
>... if I say
>	foo;
>outside of a block, I'll get a static int foo, right?

No, you're supposed to get an extern int foo (which has static storage
duration), initialized with value 0.

>	bar() { foo; }
>obviously, the compiler can't determine if I mean auto int foo, or compute
>the expression foo (I assume it assumes the latter).  This is an ambiguity
>in the grammar, yes?

Sure, the compiler can determine what to do.  You're asking it to evaluate
the expression "foo" and discard the result.  I don't know what you mean by
"ambiguity"; the reason C has lots of rules is to determine the meaning of
all valid constructs.

If you want a private variable (with scope confined to the block that is
the body of the bar() function), you must declare one.  "foo;" is not a
declaration inside a block.  The reason it works as one at the file level
is that there can be no executable code at that level.  It is not good
style in any case.

>is there any real reason for the 'auto' keyword?  Has anyone ever
>used it for anything?

"auto" is not necessary, and I don't know anyone who uses it, but I have
seen code that did, presumably to emphasize the storage class,

>is 'register int baz()' legal and if so would it make any difference anywhere.

No, a function is not in general allowed to be put into a register.
A pointer to a function is a different matter.

>What (if ever) was 'entry' used for?

It was intended for an alternate entry point to a function, as one sees
occasionally in Fortran (the canonical example being SIN and COS).
So far as I know it was never implemented anywhere.  In fact I don't
know what syntax could possibly have been intended for this.

daveb@llama.rtech.UUCP (Dave Brower) (09/01/88)

In article <1988Aug28.030747.19105@utzoo.uucp> henry@utzoo.uucp (Henry Spencer) writes:
>In article <530@accelerator.eng.ohio-state.edu> mills@baloo.eng.ohio-state.edu (Christopher Mills) writes:
>>Also, is there any real reason for the 'auto' keyword?  Has anyone ever
>>used it for anything?
>
>It's not useful, but there is probably old code somewhere that declares
>some local int variables with "auto i;" instead of "int i;".  Sigh.

Sometimes I use auto for a local variable whose address I will be taking
later.  This is a hint that I can't make it register if optimization
fever strikes

-dB
"Ready when you are Raoul!"
{amdahl, cpsc6a, mtxinu, sun, hoptoad}!rtech!daveb daveb@rtech.com <- FINALLY!