According to Steven Monai on 1/19/2010 8:11 PM: > I compile and run this program as follows: > > $ g++ -ansi -o mytest mytest.cc && ./mytest
Using -ansi generally says that you want the headers to expose ONLY the interfaces mentioned in the C89 standard. But C89 did not describe snprintf, hence your compilation failure. Filtering declarations based on various standards is something that glibc does better than newlib; this is a known weakness in newlib, and patches are thoughtfully considered. And c++ has different rules than C89 about what is provided by default, so it is entirely possible that you found a bug that should be reported to the newlib list. In the meantime, either don't use snprintf without declaring it by hand, or else don't use -ansi, since they are obviously not compatible in the current state of the headers. > > Furthermore, when I replace the cout line with a printf(), the compiler > never complains about printf(), regardless of the presence or absence of > the -ansi flag. I find that puzzling, since I'd expect printf() and > snprintf(), being related functions, to be affected in the same way by > the compilation flags. But C89 did describe printf. For a similar example, consider dprintf, which is also in the *printf family. It is not part of C99, but is part of POSIX 2008. We've already established that newlib's headers don't do the best of filtering, but on glibc systems, in order to get <stdio.h> to expose dprintf, you have to pre-define either _GNU_SOURCE or _POSIX_C_SOURCE prior to including the header, to tell the compiler that you intend to use a standard that provides more interfaces than stock C89. -- Don't work too hard, make some time for fun as well! Eric Blake e...@byu.net
signature.asc
Description: OpenPGP digital signature