Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8235371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:47:10+00:00 2026-06-07T18:47:10+00:00

I am a little puzzled. I have project that I compile with CFLAGS=-g -O2

  • 0

I am a little puzzled. I have project that I compile with

CFLAGS=-g -O2 -Wall -Wextra -Isrc/main -pthread -rdynamic -DNDEBUG $(OPTFLAGS) -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=700

Now I want to use mkdtemp and therefor include unistd.h

char *path = mkdtemp(strdup("/tmp/test-XXXXXX"));

On MacOSX the compilation gives some warnings

warning: implicit declaration of function ‘mkdtemp’
warning: initialization makes pointer from integer without a cast

but compiles through. While mkdtemp does return a non-NULL path accessing it results in a EXC_BAD_ACCESS.

Question 1: The template is strdup()ed and the result is non-NULL. How on earth can this result in an EXC_BAD_ACCESS?

Now further down the rabbit hole. Let’s get rid of the warnings. Checking unistd.h I find the declaration hidden by the pre processor.

#if     !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)
...
char    *mkdtemp(char *);
...
#endif

Adding -D_DARWIN_C_SOURCE to the build makes all the problems go away but leaves me with a platform specific build. The 10.6 man page just says

 Standard C Library (libc, -lc)
 #include <unistd.h>

Removing the _XOPEN_SOURCE from the build makes is work on OSX but then it fails to compile under Linux with

warning: ‘struct FTW’ declared inside parameter list
warning: its scope is only this definition or declaration, which is probably not what you want
In function ‘tmp_remove’:
warning: implicit declaration of function ‘nftw’
error: ‘FTW_DEPTH’ undeclared (first use in this function)
error: (Each undeclared identifier is reported only once
error: for each function it appears in.)
error: ‘FTW_PHYS’ undeclared (first use in this function)

Question 2: So how would you fix this?

The only fix I have found is to #undef _POSIX_C_SOURCE right before the unistd.h include …but that feels like an ugly hack.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:47:13+00:00Added an answer on June 7, 2026 at 6:47 pm

    You’ve asked two questions here, and I’m just going to answer the first:

    Question 1: The template is strdup()ed and the result is non-NULL. How on earth can this result in an EXC_BAD_ACCESS?

    As the warnings above tell you:

    warning: implicit declaration of function ‘mkdtemp’

    This means it couldn’t find the declaration for mkdtemp. By C rules, that’s allowed, but it’s assuming the function returns an int.

    warning: initialization makes pointer from integer without a cast

    You’ve told the compiler “I’ve got a function that returns int, and I want to store the value in a char*”. It’s warning you that this is a bad idea. You can still do it, and therefore it compiles.

    But think about what happens at runtime. The actual code you link to returns a 64-bit char*. Then your code treats that as a 32-bit int that it has to cast to a 64-bit char*. How likely is that to work?

    This is why you don’t ignore warnings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just spotted something that I am a little puzzled about, I wonder
I'm a little puzzled with QueryStrings and ActionResult I have a URL coming in
I have a little method that does some CoreGraphics drawing. Today I was using
I'm a little puzzled with this one. I have a Collection called AllProducts, which
I have a little SQL Distinct puzzle that i cannot solve (or at least
Little puzzled If i have a button in a wpf window and bind it
I've been a little puzzled with this as I have not seen many examples
I'm going through a Fortran code, and one bit has me a little puzzled.
I am a little bit puzzled as to how I can optimize my program
Little help if you don't mind. Basically, I have 3 radio boxes and a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.