|
Re: bug while wrapping const char arrays without an explicitly defined size: msg#00187programming.swig
David Beazley wrote: Marcelo Matus writes:Yes, the strings are NULL terminated, but the null character appears in the python side, char hi_a [] = {'h','e','l','l','o'}; => 'hello' char hi_b [] = "hello"; => 'hello\0' char hi_c [] = {'h','e','l','l','o', 0};=> 'hello\0' char hi_d [5] = {'h','e',0,'l','o'}; => 'he\0lo' char hi_e [6] = "he\0lo"; => 'he\0lo\0' The last '0' char is preserved since python preserve all the null chars if you use a known size. This is done in this way since people also use the char arrays as binary forms, are '0' char can appears in any place, like char octect[8]; Hence, is not neccesary you have a NULL ending character, and if there is one, is not clear you can ignore it. However, in the form char *hi = "hello"; const char* const hi = "hello"; it is clear that there will be a NULL ending character, because the size is unknown, and in most the cases (99.9999%) you are not interesting in getting the ending character explicitily Note that if you pass back to C/C++ either 'hello' or 'hello\0', both will work as espected if you are waiting for a plain 'char *', and also in the case you are waiting for char[5] or char[6]. But, anyway, I remember only a few user worrying about fully preserving the intra or final NULL characters in an array. So, if you prefer, we can always chop all the NULL characters from the end. Why is this suddenly broken? I thought issues concerning C character well, the case char hi_b [] = "hello"; it seems to be broken for several languages. I added some test lines to the arrays_global.i file, and it doesn't compile in Java, tcl nor ruby. But it seems to be working fine in perl and now in python too. Marcelo -- Dave _______________________________________________ Swig maillist - Swig@xxxxxxxxxxxxxxx http://mailman.cs.uchicago.edu/mailman/listinfo/swig |
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | warnings when using directors with multiple throw specifiers: 00187, Oren Miller |
|---|---|
| Next by Date: | Re: bug while wrapping const char arrays without an explicitly defined size: 00187, David Beazley |
| Previous by Thread: | Re: warnings when using directors with multiple throw specifiersi: 00187, Marcelo Matus |
| Next by Thread: | Re: bug while wrapping const char arrays without an explicitly defined size: 00187, David Beazley |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |