views:

193

answers:

2

I'm writing a tcp client in Delphi for a server that has a series of messages defined as c structs. Below is an example conversion of one of the messages:

struct {
    int32     Reserved;
    cstring   Name;
    int32     flags;
}

msg1 = record
  Reserved : integer;
  Name : cstring???;
  flags : integer;
end

Googling the type tells me that a cstring is different than the standard array of char I would expect to pass in this situation, but I can't seem to find out the internal representation of a cstring.

How would I represent cstring in the record for passing to the server?

A: 

The spec apparently uses the term cstring to mean an array of char followed by a null terminator instead of an actual CString type. Apparently just an irritating confusion of terminology in the spec.

Jason Southwell
OK. So what is the answer to your question? What is "the spec," and how does it define that term? (Always consult the spec for definitions before turning to outside sources.) How should we interpret that definition in Delphi terms?
Rob Kennedy
cstring was not defined in the spec and hence why I went looking for the binary representation of CString template. After asking the spec authors they updated the spec to include their definition.
Jason Southwell
A: 

There's no real difference. A "C string" is a pointer to a null-terminated array of chars, nothing more. There's no real "string type" in C like there is in Delphi. Delphi represents it with the PChar type. (Be aware that in D2009 and later, you have to know the difference between PAnsiChar and PWideChar.)

Careful, though, if the documentation is calling the array itself a C string, as opposed to a pointer to the array, that's a potential pitfall. You'll have to use an array in your record, and you'll have to know exactly how long it's supposed to be.

Mason Wheeler
CString is also a MS VC++ class. Which CString are we talking about? Anyway google for it, "interesting" results are returned...
ldsandon
Since CString was not defined in the spec, I assumed it was referring to the C++ class.
Jason Southwell