Article View: comp.os.ms-windows.programmer.misc
Article #2504difference between STUFF *stuff & STUFF stuff[]???
From: John Grant
Date: Wed, 06 Jan 1993 08:45
Date: Wed, 06 Jan 1993 08:45
45 lines
2085 bytes
2085 bytes
At the risk of appearing stupid again, I have another (perhaps obvious, but not right now at 3:30 AM) question... I had the following in my app: in my global module: #define MAXSTUFF 10 static STUFF stufftable[MAXSTUFF]; and in another module that referenced it: extern STUFF stufftable[]; Ok, that was fine and everything worked ok. I decided to change it to a heap table instead, so I declared it in global as: static STUFF *stufftable; and at startup time, allocated it: stufftable=malloc(MAXSTUFF*sizeof(STUFF)); and in the other module, I left it as: extern STUFF stufftable[]; I thought that it was ok (actually I forgot to change it), because you can use things like somefunc(...,STUFF *x,...); and somefunc(...,STUFF x[],...); interchangeably in function calling sequences, i.e. there is no difference between a pointer and the address of an array. Boy, was I surprised! When I re-built and tested it, all hell broke loose, with UAE and crashes left, right & centre. Note that I always enable every single warning when I compile and it didn't tell me there was anything wrong. Anyway, when I changed the reference to: extern STUFF *stufftable; and re-built, it ran perfectly. So, can someone tell me the difference between the following 2 statements: extern STUFF *stufftable; extern STUFF stufftable[]; with respect to the code generated when I reference stufftable, i.e.: stufftable[i].xxx=... and explain why it is so dangerous here, but it's perfectly ok to use a pointer or a [] in a function declaration. -- John A. Grant jagrant@emr1.emr.ca Airborne Geophysics Geological Survey of Canada, Ottawa
Technical Details
Message-ID:
<1993Jan6.084522.25921@emr1.emr.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!usc!cs.utexas.edu!torn!nott!emr1!jagrantShow Full Headers
Complete Article Headers
Newsgroups: comp.os.ms-windows.programmer.misc Path: arc1-ca.pugleaf.net!sparky!uunet!spool.mu.edu!sdd.hp.com!usc!cs.utexas.edu!torn!nott!emr1!jagrant From: jagrant@emr1.emr.ca (John Grant) Subject: difference between STUFF *stuff & STUFF stuff[]??? Message-ID: <1993Jan6.084522.25921@emr1.emr.ca> Organization: Energy, Mines, and Resources, Ottawa Date: Wed, 6 Jan 1993 08:45:22 GMT Lines: 45