X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,WEIRD_PORT X-Spam-Check-By: sourceware.org X-Cloudmark-SP-Filtered: true X-Cloudmark-SP-Result: v=1.0 c=1 a=8rQYtOT4BIsA:10 a=kCKDY91tEBMc+hi4YtGk8Q==:17 a=97JChTTPg6I_k2t-MmQA:9 a=soCPbofdgnB94OiCz1G3J34SelYA:4 Message-ID: <4B56745F.9070903@monai.ca> Date: Tue, 19 Jan 2010 19:11:27 -0800 From: Steven Monai User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.1.5) Gecko/20091204 Thunderbird/3.0 MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: g++: -ansi flag makes snprintf() unavailable? Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Hi folks, Here is a very simple C++ test program that uses snprintf() and then prints the result. #include #include using namespace std; int main() { char buf[10]; char c = 10; snprintf( buf, sizeof(buf), "&#x%02X;", (unsigned) ( c & 0xff ) ); cout << buf << '\n'; // printf( "%s\n", buf ); return 0; } I compile and run this program as follows: $ g++ -ansi -o mytest mytest.cc && ./mytest In Debian Lenny, using g++ version 4.3.2, the program compiles and runs successfully, producing the output I expect. However in Cygwin 1.7, using g++ version 4.3.4, I get the following compilation error: mytest.cc: In function 'int main()': mytest.cc:9: error: 'snprintf' was not declared in this scope When I remove the -ansi flag from the compilation line, the program builds and runs successfully in both Cygwin and Debian. 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. Can anyone shed some light on this behaviour? Did the interpretation of the -ansi flag change between gcc version 4.3.2 (Debian's) and 4.3.4 (Cygwin's)? Or is someone's compiler misbehaving? Best regards, -SM -- -- 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