Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
c++ - variable-length arrays
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? 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 articleOuch... 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. Mar 01 2008
|