linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* wcscat problem
@ 2006-01-19 15:38 Patrick Leslie Polzer
  2006-01-19 17:57 ` Markus Rechberger
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Patrick Leslie Polzer @ 2006-01-19 15:38 UTC (permalink / raw)
  To: linux-c-programming

[-- Attachment #1: Type: text/plain, Size: 794 bytes --]


Hello list,

why does wcscat not work like strcat does?
It seems to be leaving the null byte in (C99 source):


#define _GNU_SOURCE
#include <wchar.h>


int main (int ac, char** av)
{
        wchar_t* ws = malloc(8);
        wcscpy(ws, (wchar_t*)"abc");
        wcscat(ws, (wchar_t*)"def");
        printf("%s/%s\n", ws, (void*)ws+4); /* "abc/def" [*] */


        char* s = malloc(8);
        strcpy(s, "abc");
        strcat(s, "def");
        printf("%s/%s\n", s, s+4); /* "abcdef/ef" */

        return 0;
}

Why is this?  I also noticed the compiler (gcc4) takes "string steps"
when performing pointer arithmetics with wchar_t pointers, that's why
I needed to cast to void* in line [*].

Leslie


-- 
gpg --keyserver pgp.mit.edu --recv-keys 0x52D70289

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2006-01-22 10:30 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-01-19 15:38 wcscat problem Patrick Leslie Polzer
2006-01-19 17:57 ` Markus Rechberger
2006-01-19 18:24   ` Patrick Leslie Polzer
2006-01-19 20:52 ` Steve Graegert
2006-01-22 10:30 ` Glynn Clements

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).