This is the mail archive of the cygwin@sourceware.cygnus.com
mailing list for the Cygwin project. See the Cygwin
home page for more information.
gcc -U_WIN32 pitfalls!
- To: cygwin@sourceware.cygnus.com
- Subject: gcc -U_WIN32 pitfalls!
- From: Mumit Khan <khan@xraylith.wisc.edu>
- Date: Fri, 23 Apr 1999 21:33:11 -0500 (CDT)
Just for kicks, I tried to build a small analysis program with -U_WIN32;
this tool is essentially a filter and doesn't use any win32 specific
features, so it should be pretty safe, right?
Looks like certain typedefs are *WRONG* when you undefine _WIN32 and it
causes amazingly subtle bugs! Any code using stat for example will be
subtly but surely broken.
I'm attaching a small trivial program that should illustrate this. Here's
the header comments from the file.
This is with stock B20.1. Compiler version is no relevant here.
//
// A simple program to show the pitfall of using -U_WIN32 in your code
// under Cygwin b20.1!
//
// To build:
// $ c++ -U_WIN32 -o cyg-stat-bug cyg-stat.cc
// $ c++ -o cyg-stat-ok cyg-stat.cc
//
// Now run it giving a filename on command line:
//
// $ ./cyg-stat-bug ./cyg-stat.cc
// $ ./cyg-stat-ok ./cyg-stat.cc
//
// To find the cause of the problem (after you notice it in the output
// of course!), you need to look at the preprocessed files.
//
// $ c++ -save-temps -U_WIN32 -o cyg-stat-bug cyg-stat.cc
// $ mv cyg-stat.ii cyg-stat-bug.ii
// $ c++ -save-temps -o cyg-stat-ok cyg-stat.cc
// $ mv cyg-stat.ii cyg-stat-ok.ii
// $ diff -u3p cyg-stat-bug.ii cyg-stat-ok.ii
//
// Look for ino_t.
//
Regards,
Mumit
//
// A simple program to show the pitfall of using -U_WIN32 in your code
// under Cygwin b20.1!
//
// To build:
// $ c++ -U_WIN32 -o cyg-stat-bug cyg-stat.cc
// $ c++ -o cyg-stat-ok cyg-stat.cc
//
// Now run it giving a filename on command line:
//
// $ ./cyg-stat-bug ./cyg-stat.cc
// $ ./cyg-stat-ok ./cyg-stat.cc
//
// To find the cause of the problem (after you notice it in the output
// of course!), you need to look at the preprocessed files.
//
// $ c++ -save-temps -U_WIN32 -o cyg-stat-bug cyg-stat.cc
// $ mv cyg-stat.ii cyg-stat-bug.ii
// $ c++ -save-temps -o cyg-stat-ok cyg-stat.cc
// $ mv cyg-stat.ii cyg-stat-ok.ii
// $ diff -u3p cyg-stat-bug.ii cyg-stat-ok.ii
//
// Look for ino_t.
//
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <cstdio>
#include <iostream>
int
main (int argc, char *argv[])
{
for (int i = 1; i < argc; i++)
{
struct stat buf;
const char *path = argv[i];
int result = stat (path, &buf);
if (result == 0)
{
cerr << "st_dev = " << buf.st_dev << endl;
cerr << "st_ino = " << buf.st_ino << endl;
cerr << "st_mode = " << buf.st_mode << endl;
cerr << "st_nlink = " << buf.st_nlink << endl;
cerr << "st_uid = " << buf.st_uid << endl;
cerr << "st_gid = " << buf.st_gid << endl;
cerr << "st_rdev = " << buf.st_rdev << endl;
cerr << "st_size = " << buf.st_size << endl;
}
else
{
cerr << "cannot stat " << path;
perror ("");
}
}
return 0;
}
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com