logo       

Re: bug while wrapping const char arrays without an explicitly defined size: msg#00191

programming.swig

Subject: Re: bug while wrapping const char arrays without an explicitly defined size

Marcelo Matus writes:
> >
> And that is the way the 'char *' datatype is working, nothing has been
> changed,
> that is what we call "strings", ie, the one that always have a NULL ending
> character.
>
> The thing is that 'char*' and 'char[ANY]' are different, in C you can
> always get
> sizeof(char[ANY]) -> ANY, you don't need to use strlen because the size
> is known, C doesn't require the char[ANY] to be NULL-terminated, etc.

No, but it usually is NULL-terminated anyways. If I have:

char pathname[256] = "/whatever";

I don't expect to get a 256 character string back when I read it.

> But I will add the code to delete the ending NULL chars by default, so,
> char *, char[ANY] and char[] will look more alike.

My personal preference on this is that all strings involving char
(regardless of pointer, array, etc) default to NULL-terminated. As a
special case, char arrays with no dimensions [] should additionally be
readonly. On the other hand, if we had some documented built-in
typemaps that could be used to handle the other cases, that would be
good.

> Should we also need to add something to the docs saying that
> the same rules for the char * datatype will apply to char[ANY]
> and char[]?

Sure.

Cheers,
Dave
_______________________________________________
Swig maillist - Swig@xxxxxxxxxxxxxxx
http://mailman.cs.uchicago.edu/mailman/listinfo/swig



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise