于 2012/7/4 23:46, niXman 写道:
> The following code gives the right result when compiled without
> defined __USE_MINGW_ANSI_STDIO macro.
> But, if __USE_MINGW_ANSI_STDIO macro is defined - the result is 6.
> Why?
>
> code:
> #include <stdio.h>
> int main() {
> wchar_t buf[2];
> int len = snwprintf(buf, sizeof(buf) / 2, L"world!");
> printf("%d\n", len);
> }
>
>
> Thanks.
>
>
Without the macro, it will hit the code
#if !defined (__USE_MINGW_ANSI_STDIO) || __USE_MINGW_ANSI_STDIO == 0
#pragma push_macro("snwprintf")
#pragma push_macro("vsnwprintf")
# undef snwprintf
# undef vsnwprintf
int __cdecl __ms_snwprintf (wchar_t * __restrict__ s, size_t n, const
wchar_t * __restrict__ format, ...);
int __cdecl __ms_vsnwprintf (wchar_t * __restrict__ , size_t, const
wchar_t * __restrict__ , va_list);
__mingw_ovr
int snwprintf (wchar_t * __restrict__ s, size_t n, const wchar_t *
__restrict__ format, ...)
{
int r;
va_list argp;
__builtin_va_start (argp, format);
r = _vsnwprintf (s, n, format, argp);
__builtin_va_end (argp);
return r;
}
It will call ms's _vsnwprintf
With the macro, it will hit the code
#ifndef __NO_ISOCEXT /* externs in libmingwex.a */
__mingw_ovr
/* __attribute__((__format__ (gnu_wprintf, 3, 4))) */
__MINGW_ATTRIB_NONNULL(3)
int snwprintf (wchar_t *__stream, size_t __n, const wchar_t *__format, ...)
{
register int __retval;
__builtin_va_list __local_argv; __builtin_va_start( __local_argv,
__format );
__retval = __mingw_vsnwprintf( __stream, __n, __format, __local_argv );
__builtin_va_end( __local_argv );
return __retval;
}
It will call __mingw_vsnwprintf
Maybe someone can explain it here.
--
Best Regards,
xunxun
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Mingw-w64-public mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public