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 8377017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:33:53+00:00 2026-06-09T15:33:53+00:00

I am taking a course in C after many years programming. My instructor is

  • 0

I am taking a course in C after many years programming. My instructor is not using a POSIX machine, and I was recently penalized for using the index function in an assignment. I did some research and I notice that while index was an early part of AT&T Unix and is POSIX-compliant, it is not part of the C99 standard. I’d like gcc to help me find use of similar symbols. I am compiling on OSX with gcc 4.2 (not llvm)

My first leg of research involved noticing that my string.h file wraps the prototype for index in the following check for feature test macros:

#if !defined(_POSIX_C_SOURCE) || defined(_DARWIN_C_SOURCE)

After a little digging, I found this (in my /usr/include/sys/cdefs.h):

 /* STRICT  Defining _POSIX_C_SOURCE or _XOPEN_SOURCE restricts the
 *      available APIs to exactly the set of APIs defined by the
 *      corresponding standard, based on the value defined.
 *
 *      A correct, portable definition for _POSIX_C_SOURCE is 200112L.
 *      A correct, portable definition for _XOPEN_SOURCE is 600L.
 */

And so with this gcc command:

gcc -D _POSIX_C_SOURCE=200112L -pedantic -Wall -std=c99 -o myExec ./mySource.c

I do get a decent warning:

warning: incompatible implicit declaration of built-in function ‘index’

This confuses me, and I want to make the program fail to link as well. The reason it confuses me is, I read at opengroup.org that defining that macro should expose POSIX symbols, not hide them. So here is my question in a succinct form:

How can I make gcc 4.2 (on OSX 10.6) compile and link my program in an environment which is strictly C99 with no additional symbols available?

Ideally, I want warnings during compile and failure to link. I’m hoping that the answer does not involve telling gcc that I am writing POSIX code, when I believe that’s the opposite of what I want to tell it. What am I not understanding?

  • 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-09T15:33:54+00:00Added an answer on June 9, 2026 at 3:33 pm
    1. You’re not going to get a link error, sorry. Libraries don’t work that way. The index function is a part of the standard library. The standard library supports multiple versions of C (and POSIX) at the same time, and the macros select which prototypes get exposed.

    2. The -ansi flag is equivalent to -std=c89, so stop doing that.

    3. You are right that _POSIX_C_SOURCE exposes additional functionality, but it also specifies which version of the functionality to expose. Defining _POSIX_C_SOURCE=200112L means that index appears in <strings.h> instead of <string.h>. It’s still there. Specifying the 2008 POSIX will get rid of index entirely, since it was removed from later versions of the POSIX standard.

    4. There is a macro which means “only ANSI C”, and that is _ANSI_SOURCE.

    5. You can get a compilation error (but not a link error) by adding -Werror-implicit-function-declaration.

    $ gcc -Werror-implicit-function-declaration \
        -D_ANSI_SOURCE -pedantic -Wall -std=c99 ...
    error: implicit declaration of function 'index'
    

    This seems to work just fine on all combinations OS X 10.5/10.8, GCC 4.0/4.2.

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

Sidebar

Related Questions

I am taking a course on programming, and we're using C++. We had an
I'm taking a database theory course, and it's not clear to me after doing
I'm just starting to learn Verilog on my own after taking a course on
I am taking an intermediate programming course which stresses the use of invariants. I
I'm taking a programming languages course and we're talking about the extern C declaration.
I am only allowed to use private members in the programming course I'm taking,
Recently I've migrated to Arch Linux, after ~4 years being loyal to Ubuntu. Everything
After taking some small courses and using WPF and C# a bit I've decided
When I go back to school after Thanksgiving, I'll be taking a course in
I'm currently taking a college course on AS400 (IBM I) and i've been good

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.