Re: Enumerations in fortran 2003
- From: "James Giles" <jamesgiles@xxxxxxxxxxxxxxxx>
- Date: Sun, 25 Sep 2005 22:33:54 GMT
Richard Maine wrote:
> In article <1127622530.092059.110080@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
> "gaurav" <gauravgautam123@xxxxxxxxx> wrote:
>
>>> If I understand correctly, in the statement "enum aa = {a, b, c};"
>>> the sizeof(enum aa) can be different from sizeof(a). I believe
>>> that the OP is asking if F2003 enumerators are to be the same
>>> size as sizeof(enum aa) or sizeof(a). In particular, the sizeof
>>
>> yes, i am asking precisly this.
>
> Oh. That doesn't match my understanding of the C standard. But then
> I'm not an expert on the C standard and it is quite possible that my
> understanding is wrong.
>
> I rather thought that "enum aa = {a, b, c}" constituted a
> declaration of a, b, and c to be of the same size as the enum. I'm
> not sure how several things could work if it didn't. For example,
> I'd expect to be able to write a, b, or c to a file and then later
> read that same file data back into a variable of type aa. But if
> I'm wrong, as may well be, you'll have to consult a C expert
> instead of me. Then match what the Fortran standard says to the
> precise terminology of the C standard. If my understanding of the C
> standard is wrong, then I'm not the person to give you expert
> advice on it. (And if my understanding happens to be correct, then
> your question is based on a false premise).
I think that in both Fortran and C the enumeration literals (a,
b, and c in this case) are named constants and don't necessarily
have a size or any location in memory. They could usually,
or even always be implemented as immediate opeands or
other trickery directly in the instructions that use them. The
sizeof 'operator' does'st exist in Fortran, but in C when applied
to an expression gives the same answer as sizeof (type name)
for the type of the expression:
The sizeof operator yields the size (in bytes) of its operand,
which may be an expression or the parenthesized name of a
type. The size is determined from the type of the operand.
I'd have to dig, but it seems unlikely that C would allow any
expression to be written in binary with a different size than the
result of sizeof applied to that expression.
--
J. Giles
"I conclude that there are two ways of constructing a software
design: One way is to make it so simple that there are obviously
no deficiencies and the other way is to make it so complicated
that there are no obvious deficiencies." -- C. A. R. Hoare
.
- Follow-Ups:
- Re: Enumerations in fortran 2003
- From: glen herrmannsfeldt
- Re: Enumerations in fortran 2003
- From: Richard Maine
- Re: Enumerations in fortran 2003
- References:
- Enumerations in fortran 2003
- From: gaurav
- Re: Enumerations in fortran 2003
- From: gaurav
- Re: Enumerations in fortran 2003
- From: Richard Maine
- Re: Enumerations in fortran 2003
- From: gaurav
- Re: Enumerations in fortran 2003
- From: Richard Maine
- Re: Enumerations in fortran 2003
- From: Steven G. Kargl
- Re: Enumerations in fortran 2003
- From: gaurav
- Re: Enumerations in fortran 2003
- From: Richard Maine
- Enumerations in fortran 2003
- Prev by Date: Re: Enumerations in fortran 2003
- Next by Date: Re: moving up to f90/f95: automatic arrays, stack limits, etc
- Previous by thread: Re: Enumerations in fortran 2003
- Next by thread: Re: Enumerations in fortran 2003
- Index(es):
Relevant Pages
|