11

I am working on a project and the code contains a macro definition:

#define __USE_MISC

The code is not using it so I think it has some other purpose.

pevik
  • 4,523
  • 3
  • 33
  • 44
Bruce
  • 33,927
  • 76
  • 174
  • 262
  • I found this in `` __USE_MISC Define things common to BSD and System V Unix . But I still don't know what it does exactly. – Bruce Apr 19 '12 at 16:00

2 Answers2

14

__USE_MISC is defined in /usr/include/features.h on the condition:

#if defined _BSD_SOURCE || defined _SVID_SOURCE
# define __USE_MISC     1
#endif

__USE_MISC --> Define things common to BSD and System V Unix.

So it looks like your code wants to ensure that it's defined in any case even if both _BSD_SOURCE and _SVID_SOURCE are not defined (Since glibc 2.20, defining _DEFAULT_SOURCE enables __USE_MISC).

See feature test macros for more information.

P.P
  • 117,907
  • 20
  • 175
  • 238
  • Additionally, I'd suggest that the OP look at making sure the build environment is properly configured (and/or document the required configuration) rather than using this back-door hack. – Michael Burr Apr 19 '12 at 17:26
  • NOTE: `_BSD_SOURCE` and `_SVID_SOURCE` has been deprecated and replaced by `_DEFAULT_SOURCE` in [glibc 2.20](https://sourceware.org/git/?p=glibc.git;a=commit;h=c941736c92fa3a319221f65f6755659b2a5e0a20) (`_DEFAULT_SOURCE` has been added in [glibc 2.19](https://sourceware.org/git/?p=glibc.git;a=commit;h=c688b4196014e0162a1ff11120f6c9516be0c6cb)). – pevik Jan 09 '20 at 14:20
6

__USE_MISC is an internal detail for how the implementation's headers handle "feature test macros" that direct the compiler as to what set of standard functions should be made available to the build. As Thiruvalluvar's answer indicates, it's set up (for internal use) by the library headers if your build wants a _BSD_SOURCE or _SVID_SOURCE configuration.

Your code/build should not be dealing with that macro directly; instead it should use the documented feature test macros. glibc's docs can be found here: http://www.gnu.org/software/libc/manual/html_node/Feature-Test-Macros.html

Community
  • 1
  • 1
Michael Burr
  • 333,147
  • 50
  • 533
  • 760
  • 2
    I found myself in a situation where I needed to `-ansi -D_DEFAULT_SOURCE=__STRICT_ANSI__` because `-ansi` alone left members of `struct in6_addr` undefined. `-D_DEFAULT_SOURCE=__STRICT_ANSI__` ensured `__USE_MISC` got defined. Also see [‘struct in6_addr’ has no member named ‘s6_addr32’ with -ansi](http://stackoverflow.com/a/36222072/608639). It does not feel comfortable because I have never had to do it. – jww Mar 25 '16 at 14:48