Article View: comp.os.ms-windows.programmer.misc
Article #2565Re: difference between STUFF *stuff & STUFF stuff[]???
From: John Grant
Date: Thu, 07 Jan 1993 20:23
Date: Thu, 07 Jan 1993 20:23
50 lines
2242 bytes
2242 bytes
In article <726351962snz@chrism.demon.co.uk> chris@chrism.demon.co.uk writes: >In article <1993Jan6.084522.25921@emr1.emr.ca> jagrant@emr1.emr.ca writes: > >>At the risk of appearing stupid again, I have another (perhaps >>obvious, but not right now at 3:30 AM) question... >> [ Lots of stuff deleted] >> >>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 >> > >The difference is very simple: > > extern STUFF *stufftable > >tells the complier that you have a global variable which is a POINTER to >a "stufftable". ie, the global quantity is a 2 or 4-byte pointer. > > extern STUFF stufftable[] > >tells the compiler that you have a global ARRAY of STUFFs. > >The two things are totally different. The reason that it doesn't matter >in a function declaration is that passing the name of an array to a function >is the same as passing a pointer to the start of the array. > >Hope this helps, Yes, it's me again and less stupid... Thanks to all you responded. The essential difference is that: extern STUFF stufftable[]; assumes that stufftable resides in the current data segment, when in fact it is a pointer to the stuff on the heap. -- John A. Grant jagrant@emr1.emr.ca Airborne Geophysics Geological Survey of Canada, Ottawa
Technical Details
Message-ID:
<1993Jan7.202312.22886@emr1.emr.ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!olivea!spool.mu.edu!uwm.edu!cs.utexas.edu!torn!nott!emr1!jagrantReferences:
<1993Jan6.084522.25921@emr1.emr.ca> <726351962snz@chrism.demon.co.uk>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!olivea!spool.mu.edu!uwm.edu!cs.utexas.edu!torn!nott!emr1!jagrant From: jagrant@emr1.emr.ca (John Grant) Newsgroups: comp.os.ms-windows.programmer.misc Subject: Re: difference between STUFF *stuff & STUFF stuff[]??? Message-ID: <1993Jan7.202312.22886@emr1.emr.ca> Date: 7 Jan 93 20:23:12 GMT References: <1993Jan6.084522.25921@emr1.emr.ca> <726351962snz@chrism.demon.co.uk> Organization: Energy, Mines, and Resources, Ottawa Lines: 50