TIP: Click on subject to list as thread! ANSI
echo: c_echo
to: Jasen Betts
from: andrew clarke
date: 2003-08-10 09:24:50
subject: Bob`s questi

Thu 2003-08-07 18:15, Jasen Betts (3:640/1042) wrote to andrew clarke:

 JB>>> typedef struct moo
 JB>>>   {
 JB>>>  int foo;
 JB>>>  char bar;
 JB>>>   } moo;

 JB>>> is   sizeof(moo) * 100   always the same as   sizeof( moo[100] )

 ac>> moo[100] is not valid, but I think you mean:

 JB> My compilers don't complain... are you shure?

Aha!  I was wrong, and I can I explain why.  The problem was that (almost
always) whenever someone uses the sizeof operator they use brackets around
the expression in a redundant way, so I've become used to mentally
stripping away the brackets in my mind, but in your case you actually did
mean to use brackets around the expression!  Because moo[100] is a data
type, not a variable, the brackets are required, so:

size_t i = sizeof moo[100];          /* syntax error */
size_t j = sizeof(moo[100]);         /* OK */
size_t k = sizeof(struct moo[100]);  /* OK */

Also I don't recall ever seeing anyone use a data type like an array
without giving it a variable name.  I could be just losing my mind though.

Um, ignore my previous post.

Maybe this one too.

Pretend it never happened.

-- mail{at}ozzmosis.com

--- timEd/FreeBSD 1.11.b1
* Origin: Blizzard of Ozz, Mt Eliza, Melbourne, Australia (3:633/267)
SEEN-BY: 633/267 270
@PATH: 633/267

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.