From: MCzapski AT openplus DOT com DOT au (Michael Czapski) Subject: I: gcc ... -U_WIN32 ... may cause problems 27 Aug 1998 18:45:15 -0700 Message-ID: <01BDD20D.B63709B0.MCzapski.cygnus.gnu-win32@openplus.com.au> Reply-To: "MCzapski AT openplus DOT com DOT au" Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: "gnu-win32 AT cygnus DOT com" Hello All, I am currently working on a 'source-portable' application, intended to run natively under Win32, various flavours of Unix as well as OpenVMS. Usually I develop using Microsoft Developer Studio (VC++ 5.0, Intel), re-build and test under Cygwin32 B19.3 (EGCS 1.0.2), re-build and test on Linux (gcc 2.7.2, Intel), re-build and test on OpenVMS/VAX 7.0 (DECC 5.5). This arrangements allows me to conveniently test and resolve 'gross' portability issues. When I am sufficiently far advanced with the project I will build the application on DEC Unix, OpenVMS/AXP and, possibly, other platforms. I use the same GNUmakefile for Cygwin32 and Linux (will use for other Unix(es) as well). Since gcc under Cygwin32 does not pre-define "__unix__" or "__unix" or "unix", as is the case under Linux, and in the Cygwin32/EGCS/gcc environment _WIN32 is defined the same as in the MS VC++ environment I had to code #if defined(_WIN32) && !defined(__CYGWIN32__) in a number of places. This was required to ensure that Windows NT-specific service code is not compiled under Cygwin32 but unix-specific daemon code is compiled instead, for example. To avoid coding #if defined construct as shown I decided to undefine _WIN32 when compiling in Cygwin32 environment by using a command line of a form "gcc ... -U_WIN32 ...". Before I did that the application worked fine however as soon as I did undefined _WIN32 it started to misbehave. It turned out, after some investigations, that the 'stat' system call, which worked fine with _WIN32 defined, no longer works and causes stack corruption with the resulting SEGV. It turned out, after further investigation, that the 'missing' _WIN32 affects unistd.h header file. If _WIN32 is defined just prior to #include and undefined just after all is well otherwise the problem repeats. It turned out, after further investigation, that '__MS_types__' is defined in unistd.h and that this is what makes all the difference. Now I code that as: #if defined(__CYGWIN32__) && !defined(_WIN32) # define __MS_types__ /* this breaks stat function if not defined */ # define _MS_types_DEFINED /* at the time unistd.h is included */ #endif #include #if defined(__CYGWIN32__) && defined(_MS_types_DEFINED) # undef __MS_types__ # undef _MS_types_DEFINED #endif This way I avoid defining _WIN32, can safely (?) undefine _WIN32 and code on the basis of 'if _WIN32 is not defined than it must be Unix or VMS' :-). Since I found that workaround I stopped poking around to see what exactly breaks the 'stat'. If anyone knows or finds out please let me know :-). This message may, perhaps, save somebody a great deal of hassle in the future :-) Thanks Cygnus, Sergey and all other contributors for Cygwin32 and all related bits. ------------------ Cheers ... Michael Czapski - For help on using this list (especially unsubscribing), send a message to "gnu-win32-request AT cygnus DOT com" with one line of text: "help".