Re: stdio.h cannot be compiled with -std= compiler option

Keith Marshall <[email protected]>
Newsgroups gmane.comp.gnu.mingw.user
Organization MinGW.org Project
Message-ID <[email protected]>
On 11/01/19 09:03, Eli Zaretskii wrote:
> With the latest MinGW runtime 5.2, this one-line program:
> 
>   #include <stdio.h>
> 
> doesn't compile if GCC is invoked with a -std= option:
> 
>   D:\usr\eli\data>gcc -std=c9x -c stdio.c
>   In file included from stdio.c:1:0:
>   d:\usr\include\stdio.h:790:34: error: unknown type name '__off64_t'
>    typedef union { __int64 __value; __off64_t __offset; } fpos_t;
> 				    ^~~~~~~~~
> 
> AFAICT, this happens because stdio.h does this:
> 
>   #if !(defined __STRICT_ANSI__ || defined (__NO_MINGW_LFS)) \
>    && defined (__MSVCRT__)
>   # define __need___off64_t
>   #endif

So, for any -std= option which implies __STRICT_ANSI__, the request to
typedef __off64_t isn't specified, but it is now unconditionally
required by the somewhat more opaque typedef for ANSI standard type fpos_t.

Thanks.  The attached patch should fix this.

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F

_______________________________________________
MinGW-Users mailing list
[email protected]

This list observes the Etiquette found at
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.osdn.me/mailman/listinfo/mingw-users
Also: mailto:[email protected]?subject=unsubscribe
stdio-bugfix.patch (text/x-patch, 2.5 KB)
# HG changeset patch
# Parent b747e2b4b24d0ba46a2bc8b23bc782bfb9bad9db
Fix <stdio.h> typedef omission.

* include/stdio.h (__need___off64_t) [__MSVCRT__]: Require, but...
[!(__STRICT_ANSI__||__NO_MINGW_LFS)]: ...remove this exclusion filter.
[!__MSVCRT__] (__need___off32_t): Require this alternative.
(sys/types.h): Include unconditionally.

diff --git a/mingwrt/include/stdio.h b/mingwrt/include/stdio.h
--- a/mingwrt/include/stdio.h
+++ b/mingwrt/include/stdio.h
@@ -5,11 +5,11 @@
  * standard input and standard output streams.
  *
  * $Id$
  *
  * Written by Colin Peters <[email protected]>
- * Copyright (C) 1997-2005, 2007-2010, 2014-2018, MinGW.org Project.
+ * Copyright (C) 1997-2005, 2007-2010, 2014-2019, MinGW.org Project.
  *
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
  * copy of this software and associated documentation files (the "Software"),
  * to deal in the Software without restriction, including without limitation
@@ -73,28 +73,29 @@
   * dependent on the POSIX.1-2008 feature test)...
   */
 # define __need_off_t
 # define __need_ssize_t
 #endif
-#if !(defined __STRICT_ANSI__ || defined (__NO_MINGW_LFS)) \
- && defined (__MSVCRT__)
- /* ...while this is required to support our fseeko64() and ftello64()
-  * implementations, (neither of which is in any way standardized)...
+
+/* Although non-standard themselves, we also need either one or other
+ * of the following pair of data types, from <sys/types.h>, because our
+ * standard fpos_t is opaquely defined in terms of...
+ */
+#ifdef __MSVCRT__
+ /* ...an explicitly 64-bit file offset type, for MSVCRT.DLL users...
   */
 # define __need___off64_t
+#else
+ /* ...or a 32-bit equivalent, for pre-MSVCRT.DLL users.
+  */
+# define __need___off32_t
 #endif
-/* It is sufficient to test for just one define from each of the two
- * preceding groups...
+
+/* Note the use of the #include "..." form here, to ensure that we get
+ * the correct header file, relative to the location of this <stdio.h>
  */
-#if defined __need_off_t || defined __need___off64_t
- /* ...to identify a requirement for selective inclusion of one or more
-  * of these type definitions from "sys/types.h"; (note that we use the
-  * #include "..." form here, to ensure that we get the correct header
-  * file, relative to the location of this <stdio.h>).
-  */
-# include "sys/types.h"
-#endif
+#include "sys/types.h"
 
 #ifndef __VALIST
  /* Also similarly, for the va_list type, defined in "stdarg.h"
   */
 # if defined __GNUC__ && __GNUC__ >= 3
signature.asc (application/pgp-signature, 836 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQIcBAEBAgAGBQJcOQLEAAoJEMCtNsY0flo/AREQAKauBrxC/Kc9la5oQHa8UfDc
gcxgVw6NSh6bbiZIhOp0z7nYpgxNCTnbPa/2H2ibokKOko2IgQo6DA8+o1oCVmIV
MmpX2jGoFIZjJFlXcB8JoUdgkYxmK4Qg2wyKJqNh68Vh73hHiJHD1hhHwpGT94fD
dEkv24HDUgbwYd+GU5XW/FvCZ0hoZxyZllEcPjWtxig4L+Xyw8KcVXdZVxUset6I
eAM7m1SNRW1FBGK7pf08/BPUk04D4c9Ik/haAzG+HvGnhkXK8WtajM6zlBpZvXOE
AnI2sklZCzufKRyDp0aG0UCBGng/X3ZoIZNAVTnxXdJ/QmLmUNgqwc6Ras1WPiif
1rn1C4RcGAui71NKvkrYMJTwYocTOLvjFS7JQgYNhyDxbvy9Ky1V1KVdy+3jJGj6
sHnQqObvNUkXHOo7cGAuPoHxqloFNV1cicQLjAH/gcz9MMfrSTqRlrE8nyaQCRpJ
zmHu2RFmSEqV0Xz8ZsDIJSrkcZE3LCN2P8kAzKcZfl0MtSpGvrxpyZM+722CfyUx
7KWlfi/1BY+PQcqCVoMoAfK3BKmeKJGnELMIdTHuT9IV9/k0tEcnPxnMJRDoH8d1
h3DPYyUn36fy8DPHRKiJWvApv44bX3xmZdCfTy6pjgaPPhhsg9vzZvKkY0oO2u6f
s7ZphgBY7+z6+nHBGzib
=N4Ti
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.