X-Recipient: archive-cygwin@delorie.com
X-SWARE-Spam-Status: No, hits=-0.6 required=5.0	tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,T_TO_NO_BRKTS_FREEMAIL
X-Spam-Check-By: sourceware.org
Message-ID: <4D6FC5BE.7030601@gmail.com>
Date: Thu, 03 Mar 2011 16:45:50 +0000
From: Pete Batard <pbatard@gmail.com>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.14) Gecko/20110221 Thunderbird/3.1.8
MIME-Version: 1.0
To: cygwin@cygwin.com
Subject: w32api/include/winbase.h rev. 1.101, OVERLAPPED and -std=c99
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
X-IsSubscribed: yes
Mailing-List: contact cygwin-help@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Hi,

rev 1.101 of winbase.h from 2010.08.24 introduces an anonymous structure 
and union to the OVERLAPPED definition [1].

Unfortunately, this only works when compiling with -std=gnu99 (default), 
but not with -std=c99.

The following demonstrates the problem:

----------------------------------------------------------------------
$ cat > overlapped_test.c << _EOL
#include <stdio.h>
#include <windows.h> 	/* includes winbase.h */
int main(int argc, char** argv) {
     OVERLAPPED ov;

     printf("size of OVERLAPPED: %d\n", sizeof(ov));
     return 0;
}
_EOL

$ gcc -std=gnu99 -o overlapped_test overlapped_test.c

$ ./overlapped_test.exe
size of OVERLAPPED: 20

$ gcc -std=c99 -o overlapped_test overlapped_test.c

$ ./overlapped_test.exe
size of OVERLAPPED: 12
----------------------------------------------------------------------

The main issue appears to be that, since C99 does not support GNU99 
anonymous structs/unions, it simply ignores them. But this wreaks havoc 
on any source compiled in c99 mode that exchanges an OVERLAPPED with the 
OS. This usually results in an "invalid handle error" from Windows.

Any application compiled in C99 mode and using OVERLAPPED is therefore 
expected to break, and we have seen that issue after people upgraded 
their cygwin installation and tried recompiling libusb [2]. Our current 
workaround is to switch to gnu99, but with a source that is common to 
both MSVC, MinGW and cygwin, GNU extensions is something we would like 
to avoid. Also, the problem seems to have now spread to the latest 
MinGW32 now (are they reusing cygwin's winbase.h?).

We would appreciate if you could look into this and ensure that 
winbase.h is C99 compliant.

Regards,

/Pete


[1] 
http://cygwin.com/cgi-bin/cvsweb.cgi/src/winsup/w32api/include/winbase.h.diff?r1=1.100&r2=1.101&cvsroot=src&f=h
[2] 
http://git.libusb.org/?p=libusb-pbatard.git;a=commit;h=fb33bf26916dae3a443c9d831d5f9985f58bcc6b;js=1

--
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

