Skip to content

Instantly share code, notes, and snippets.

@tkil
Created June 18, 2013 15:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkil/5806218 to your computer and use it in GitHub Desktop.
Save tkil/5806218 to your computer and use it in GitHub Desktop.
/*
Compiling this code gives me a warning about old-style casts:
$ g++ -Wold-style-cast -o g++-warnings-check g++-warnings-check.cpp -lz
g++-warnings-check.cpp: In function ‘int main()’:
g++-warnings-check.cpp:49:20: warning: use of old-style cast [-Wold-style-cast]
"deflateInit" is actually a macro:
#define deflateInit(strm, level) \
deflateInit_((strm), (level), ZLIB_VERSION, (int)sizeof(z_stream))
Which expands to the following, which indeed has an old-style cast
in it:
deflateInit_((&strm), ((-1)), "1.2.7", (int)sizeof(z_stream));
^^^^^^^^^^^^^^^^^^^^^
But I thought that zlib.h would be considered a system header, so
any macros defined in there would have immunity from most warnings.
From the manual:
2.8 System Headers
==================
The header files declaring interfaces to the operating system and
runtime libraries often cannot be written in strictly conforming
C. Therefore, GCC gives code found in "system headers" special
treatment. All warnings, other than those generated by `#warning'
(*note Diagnostics::), are suppressed while GCC is processing a
system header. Macros defined in a system header are immune to a
few warnings wherever they are expanded. This immunity is granted
on an ad-hoc basis, when we find that a warning generates lots of
false positives because of code in macros defined in system
headers.
System is Fedora 18 x86-64, gcc 4.7.2, zlib 1.2.7 (both from rpm).
*/
#include <string.h>
#include <zlib.h>
int main()
{
z_stream_s strm;
memset( &strm, 0, sizeof( strm ) );
const int rc = deflateInit( &strm, Z_DEFAULT_COMPRESSION );
return rc;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment