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

c++.dos - array with no size

↑ ↓ ← noobi <noobi_member pathlink.com> writes:
My C book say that we can to declare an array without specify the size

Like this :

char arraywithnosize [];

But i get an error when i compile it : "size of array is not know"

My book is bad ?
Jul 13 2003
↑ ↓ → Heinz Saathoff <hsaat bre.ipnet.de> writes:
noobi schrieb...
 My C book say that we can to declare an array without specify the size
 
 Like this :
 
 char arraywithnosize [];
 
 But i get an error when i compile it : "size of array is not know"
 
 My book is bad ?

You can't allocate a array with no size specified. But you can use this in other situations: 1) declare id as external array extern char array[]; This tells the compiler that the name array exist in another file and that it is an array (and not a pointer!) 2) declare it as a function parameter void DoIt(int size, char array[]); This is equivalent to void DoIt(int size, char *array); 3) declare an open array as last member of a struct struct Data { int size; char array[]; }; Now it's possible to dynamically allocate storage. Example: #define ASIZE 200 int i; struct Data *my_data = malloc(sizeof(struct Data) + ASIZE*sizeof(char)); /* Initialize it */ my_data->size = ASIZE; for(i=0; i<ASIZE; ++i) my_data->array[i]=0; Hope this helps, - Heinz
Jul 14 2003