Skip to content

Instantly share code, notes, and snippets.

@lazka
Created February 11, 2022 08:27
Show Gist options
  • Save lazka/4749c74249a3918a059d944040aca4a3 to your computer and use it in GitHub Desktop.
Save lazka/4749c74249a3918a059d944040aca4a3 to your computer and use it in GitHub Desktop.
#ifdef __GNUC__
#define G_GNUC_CHECK_VERSION(major, minor) \
((__GNUC__ > (major)) || \
((__GNUC__ == (major)) && \
(__GNUC_MINOR__ >= (minor))))
#else
#define G_GNUC_CHECK_VERSION(major, minor) 0
#endif
#define G_STRINGIFY(macro_or_string) G_STRINGIFY_ARG (macro_or_string)
#define G_STRINGIFY_ARG(contents) #contents
#if (G_GNUC_CHECK_VERSION(4, 6) || \
__clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 4))
#define _GLIB_GNUC_DO_PRAGMA(x) _Pragma(G_STRINGIFY (x))
#define GLIB_DEPRECATED_MACRO _GLIB_GNUC_DO_PRAGMA(GCC warning "Deprecated pre-processor symbol")
#define GLIB_DEPRECATED_MACRO_FOR(f) \
_GLIB_GNUC_DO_PRAGMA(GCC warning G_STRINGIFY (Deprecated pre-processor symbol: replace with #f))
#else
#define GLIB_DEPRECATED_MACRO
#define GLIB_DEPRECATED_MACRO_FOR(f)
#endif
#define PySomethingDeprecated(op) (op) GLIB_DEPRECATED_MACRO
#define PySomethingDeprecated2(op) (op) GLIB_DEPRECATED_MACRO_FOR(SomethingCompletelyDifferent)
int main(void)
{
PySomethingDeprecated (0);
PySomethingDeprecated2 (42);
return 0;
}
@lazka
Copy link
Author

lazka commented Feb 11, 2022

$ gcc a.c
a.c: In function 'main':
a.c:29:13: warning: Deprecated pre-processor symbol
   29 |     PySomethingDeprecated (0);
      |             ^~~~~~~~~~~~~~~~~~
a.c:30:13: warning: Deprecated pre-processor symbol: replace with "SomethingCompletelyDifferent"
   30 |     PySomethingDeprecated2 (42);
      |             ^~~~~~~~~~~~~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment