This is the mail archive of the
cygwin
mailing list for the Cygwin project.
snprintf() with g++ -std=c++98: error: 'snprintf' was not declared in this scope
- From: Denis Excoffier <cygwin at Denis-Excoffier dot org>
- To: cygwin at cygwin dot com
- Date: Wed, 4 Apr 2012 15:32:20 +0200
- Subject: snprintf() with g++ -std=c++98: error: 'snprintf' was not declared in this scope
Hello,
It could be that snprintf() is not properly declared in <stdio.h>.
Take the following foo.c:
% cat foo.c
#include <stdio.h>
int main(void)
{
char buf[10];
snprintf(buf, 10, "%i", 0);
return 0;
}
%
In C, perhaps after a remark from Markus
(http://sourceware.org/ml/cygwin/2009-04/msg00435.html), no compiler
message is produced:
% gcc -xc -std=c90 -c foo.c
% gcc -xc -std=c99 -c foo.c
%
On the other hand, for C++, a compiler message is produced:
% gcc -xc++ -std=c++98 -c foo.c
foo.c: In function 'int main()':
foo.c:6:28: error: 'snprintf' was not declared in this scope
%
% gcc -xc++ -std=c++0x -c foo.c
foo.c: In function 'int main()':
foo.c:6:28: error: 'snprintf' was not declared in this scope
%
Replacing <stdio.h> with <cstdio> produces the same result.
Shouldn't snprintf() (and vsnprintf() etc.) be declared in
<stdio.h> also for the C++ language/standard, especially c++0x?
Regards,
Denis Excoffier.
--
Problem reports: http://cygwin.com/problems.html
FAQ: http://cygwin.com/faq/
Documentation: http://cygwin.com/docs.html
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple