On Tue, 29 Jan 2002, David Beers wrote:

> char name[1]
> CharPtr name;
> char *name;
> 
> I thought these 3 things were the same thing.
> But when I use DmStrCopy to populate a field in the database with one 
> of these types only char name[1] seems to work. The rest seem to 
> result in garbage in the field.
> 

have you actually defined name, when declared as a pointer?


  char *name;
  StrCopy(name, "foo");  // error, name doesn't point anywhere
 
  char *name;
  name = MemPtrNew(10);
  StrCopy(name, "foo");  // ok, now name is defined


  char name[1];
  StrCopy(name, "foo");  // not ok, name not long enough to hold foo. 


the last one will appear to work but will bite you at some point.


Si.


> ******
> I lamely suggested that the problem might have to do with the fact 
> that pointers and arrays aren't /exactly/ the same thing, but I 
> couldn't explain why referring to an array seemed to work but 
> referring to a pointer did not.
> 
> His answer expresses our mutual confusion:
> 
> AS I understood it, when you define an array -
> 
> char name[1];
> 
> name on its own is pointer reference to the first element of the 
> array. i.e 
> 
> char *y = name;
> 
> points to name[0].
> 
> So what I don't get is if name translates to a charptr why does
> DmStrCopy(s, offset, UserRecord->name)
> 
> work ok,
> but when you actually replace that with something defined as a 
> charptr it doesn't work.
> 
> ******
> 
> I tried to find an answer in the KB, but no luck. Thanks in advance 
> for taking the time to help a bunch of newbies!
> 
> --
> Sent using One-Touch Mail by JP Mobile.
> 
> 



-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/tech/support/forums/

Reply via email to