Subject: Re: A *really* off question
To: John A. Maier <johnam@mail.kemper.org>
From: Richard Rauch <rkr@rkr.kcnet.com>
List: netbsd-users
Date: 01/05/2000 19:49:47
Someone else has already answered you (and my knowledge of qt is quite
limited). However, I do know C. You asked whether sizeof knew the size
of your resized array. The answer is: NO.
sizeof is a _compile_time_operator_, not a function. It also works
strictly on type information.
At the risk of beating a dead horse:
int integers [32];
int *ints = integers;
printf ("Size of {integers} == %d\n"
"Size of {ints} == %d\n",
sizeof (integers), sizeof (ints) );
On a typical 32-bit system, the first %d will be 128; the second will be 4
(your actual mileage may vary). That's because the compiler can locally
see that {integers} is an array of fixed size, but about {ints} it only
knows that it's a pointer; it has no idea how much memory is associated
with {ints}. (Alright, in this trivial example, it could analyze the
program flow and since {ints} isn't {volatile}...but the C standard
doesn't let the compiler be that clever, as far as I know.)
"I probably don't know what I'm talking about." --rkr@rkr.kcnet.com