www.digitalmars.com Home | Search | C & C++ | D | DMDScript | News Groups | index | prev | next
Archives

D Programming
D
D.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

↑ ↓ ← John <smith mail.com> writes:
int main(int argc, char *argv[argc])
{
	return sizeof argv;
}

Is this must return 4?
Feb 27 2008
↑ ↓ Jan Knepper <jan smartsoft.us> writes:
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
↑ ↓ John <smith mail.com> writes:
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
John <smith mail.com> writes:
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
↑ ↓ → John <smith mail.com> writes:
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
→ Jan Knepper <jan smartsoft.us> writes:
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