| Thread overview | ||||||||
|---|---|---|---|---|---|---|---|---|
|
February 27, 2008 variable-length arrays | ||||
|---|---|---|---|---|
| ||||
int main(int argc, char *argv[argc])
{
return sizeof argv;
}
Is this must return 4?
| ||||
February 27, 2008 Re: variable-length arrays | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John | You're asking to return the size of a pointer... A pointer is 4 bytes on 32 bits Windows... John wrote: > int main(int argc, char *argv[argc]) > { > return sizeof argv; > } > > Is this must return 4? -- ManiaC++ Jan Knepper But as for me and my household, we shall use Mozilla... www.mozilla.org | |||
February 28, 2008 Re: variable-length arrays | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Jan Knepper | int main(int argc, char *argv[argc])
{
char *vec[] = {"foo", "bar", "google"};
return sizeof vec;
}
But why this returns 12?
VLAs in both cases are the same.
| |||
February 28, 2008 Re: variable-length arrays | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John | Ouch...
int main(int argc, char *argv[argc])
{
int n = 2;
++n;
char *vec[n] = {"foo", "bar", "google"};
return sizeof vec;
}
scppn -A -v2 +all -6 test.c
Digital Mars C/C++ Compiler Version 8.50.4n
Copyright (C) Digital Mars 2000-2006. All Rights Reserved.
Written by Walter Bright
www.digitalmars.com
'test.c'
main
Internal error: init.c 1514
--- errorlevel 1
| |||
March 01, 2008 Re: variable-length arrays | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John | vec is an array of 3 pointers of 4 bytes each... 3 * 4 = 12 last time I checked... John wrote: > int main(int argc, char *argv[argc]) > { > char *vec[] = {"foo", "bar", "google"}; > return sizeof vec; > } > > But why this returns 12? > VLAs in both cases are the same. -- ManiaC++ Jan Knepper www.janknepper.com But as for me and my household, we shall use Mozilla... www.mozilla.org | |||
March 03, 2008 Re: variable-length arrays | ||||
|---|---|---|---|---|
| ||||
Posted in reply to John | And what about bottom?
== Quote from John (smith@mail.com)'s article
> Ouch...
> int main(int argc, char *argv[argc])
> {
> int n = 2;
> ++n;
> char *vec[n] = {"foo", "bar", "google"};
> return sizeof vec;
> }
> scppn -A -v2 +all -6 test.c
> Digital Mars C/C++ Compiler Version 8.50.4n
> Copyright (C) Digital Mars 2000-2006. All Rights Reserved.
> Written by Walter Bright
> www.digitalmars.com
> 'test.c'
> main
> Internal error: init.c 1514
> --- errorlevel 1
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply