c++ - variable-length arrays
- John (5/5) Feb 27 2008 int main(int argc, char *argv[argc])
- Jan Knepper (8/14) Feb 27 2008 You're asking to return the size of a pointer...
- John (7/7) Feb 27 2008 int main(int argc, char *argv[argc])
- John (17/17) Feb 27 2008 Ouch...
- John (2/19) Mar 02 2008
- Jan Knepper (9/17) Mar 01 2008 vec is an array of 3 pointers of 4 bytes each...
int main(int argc, char *argv[argc])
{
return sizeof argv;
}
Is this must return 4?
Feb 27 2008
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
Feb 27 2008
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.
Feb 27 2008
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
Feb 27 2008
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
Mar 02 2008
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
Mar 01 2008









John <smith mail.com> 