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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T12:59:09+00:00 2026-05-30T12:59:09+00:00

I normally wouldn’t do this, but the project I’m currently working on requires a

  • 0

I normally wouldn’t do this, but the project I’m currently working on requires a couple functions that are in a c source file.

extern "C" {
    int words(char sentence[]);
    int match(char str[], char sentence[], int n);
}

I simply want to know, where is the best place to add these prototypes to the linking functions in c?

Should it be added to the c++ source file (in my case, command.cpp), or the c/c++ header? (command.h)

  • 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-05-30T12:59:11+00:00Added an answer on May 30, 2026 at 12:59 pm

    The least error-prone way is to put the declarations in a shared C & C++ header file, and #ifdef the extern "C" { to only be used by the C++ compiler (it’s a syntax error in C):

    #ifdef __cplusplus
    extern "C" {
    #endif
      int words(char sentence[]);
      int match(char str[], char sentence[], int n);
    #ifdef __cplusplus
    }
    #endif
    

    I personally also like this variant of pre-#defining a macro for the unscoped extern syntax:

    #ifdef __cplusplus
    #define CFUN extern "C"
    #else
    #define CFUN
    #endif
    
    CFUN int words(char sentence[]);
    CFUN int match(char str[], char sentence[], int n);
    

    This keeps the messy #ifdef stuff localised. You can place it in one of your project-wide header files and use the CFUN specifier anywhere. You may want to prefix the name of the CFUN macro if it’s likely to collide with an existing definition.

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

Sidebar

Related Questions

Normally i wouldn't put a title like this in the question, but i'm pretty
While I wouldn't normally create a page like this, please know this is a
I wouldn't normally paste an image, I would provide the code as text, but
Is there a way to speed up PostgreSQL's createdb command? Normally I wouldn't care,
I normally would create a limited rights user and run the process under that
Normally I would just do this. $str = preg_replace('#(\d+)#', ' $1 ', $str); If
Normally I would have one junit test that shows up in my integration server
The way you would normally include a script is with source eg: main.sh: #!/bin/bash
I have a Rakefile with a Rake task that I would normally call from
I'm using xcodebuild to compile my project. I use this on the command line:

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.