public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Defining Arrays
@ 2004-03-05  3:45 Nuwan Kodagoda
  0 siblings, 0 replies; 2+ messages in thread
From: Nuwan Kodagoda @ 2004-03-05  3:45 UTC (permalink / raw)
  To: gcc-help

Hi,

	I am very confused about the way arrays are initialized under g++.  (I am 
using Red Hat Linux 9)

	int size;
	cin >> size;
	int myarray[size];

	According to what I had known earlier this should not be possible since 
the size of the array should be a constant.

	But this seems to work perfectly under g++.  To my knowledge in Standard 
C++ you are not allowed to use a variable during a array declaration.

	If you can create dynamic arrays this way, why bother using dynamic arrays 
using pointers ?

	e.g.

	int size;
	cin >> size;
	int * pmyarray = new int[size];


Nuwan

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Defining Arrays
@ 2004-03-05 12:08 Wayne
  0 siblings, 0 replies; 2+ messages in thread
From: Wayne @ 2004-03-05 12:08 UTC (permalink / raw)
  To: gcc-help

If you take a minute to check out the GCC documentation, or google
on it, wou will find that this is a fallout of a partial 
implementation of some C99? functionality.  One important note
to keep in mind about the two different ways you dynamically
created arrays.  The first creates an array on the stack, which
is very limited space, the second creates it on the usually
much larger heap.  They are not equivalent means of doing the
same thing.

Wayne

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2004-03-05 12:08 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-03-05  3:45 Defining Arrays Nuwan Kodagoda
2004-03-05 12:08 Wayne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).