Re: Enumerations in fortran 2003



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


.



Relevant Pages

  • Re: Enumerations in fortran 2003
    ... >> that the OP is asking if F2003 enumerators are to be the same ... That doesn't match my understanding of the C standard. ... write a, b, or c to a file and then later read that same file data back ...
    (comp.lang.fortran)
  • Re: "Mastering C Pointers"....
    ... I'm not talking about your pointer response, which was generally good, as I ... Together they will help you understand pointers. ... >> Maybe for understanding the C standard. ... > principles laid out in the Standard is vital. ...
    (comp.lang.c)
  • Re: Null terminated strings: bad or good?
    ... conforming, which doesn't include any program that does a ... for sizeof is to have an implementation limi which is a maximum size for ... this is not something the standard says explicitly; ... standard's specifications for the semantics of sizeof are otherwise ...
    (comp.std.c)
  • Re: "Mastering C Pointers"....
    ... >> standard that defines the language you are using. ... The real question was about pointers. ... > wonder why you're being such a pedant. ... > Maybe for understanding the C standard. ...
    (comp.lang.c)
  • Re: Whats the deal with size_t?
    ... dimensions are unknown at the time of writing. ... If you're talking about address ) + offset, ... [why does the compiler know about sizeof but not about size_t? ... standard, defualt index variable, which doesn't hold a size. ...
    (comp.lang.c)