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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:44:13+00:00 2026-06-09T06:44:13+00:00

So, while being schooled by James Kanze and Loki Astari about C linkage ,

  • 0

So, while being schooled by James Kanze and Loki Astari about C linkage, I was wondering about this:

extern "C" int foo1 (void (*)());
extern "C" { int foo2 (void (*)()); }

After my schooling, I think it must be that foo1 only takes a function pointer with C++ linkage, while foo2 only takes a function pointer with C linkage. Is my understanding correct? Are there specific references in the C++ standard that explain the differences in my example above?

Edit: To make it easier for everyone to follow along here’s a pastebin with the relevant part from the C++ 11 draft standard.

  • 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-09T06:44:15+00:00Added an answer on June 9, 2026 at 6:44 am

    foo1 takes a pointer to a C function as shown in [dcl.link] 7.5p4

    In a linkage-specification, the specified language linkage applies to
    the function types of all function declarators, function names with
    external linkage, and variable names with external linkage declared
    within the linkage-specification. [Example:

    extern "C" void f1(void(*pf)(int));
                                                                     // the name f1 and its function type have C language
                                                                     // linkage; pf is a pointer to a C function

    The example applies directly to foo1 and the added emphasis highlights what I think is the reason. The function’s parameter lists contains a function declarator for a parameter, and all function declarators are affected by the linkage specification. This applies to both braced and non-braced linkage specifications.

    Some differences when not using braces are that names are automatically extern and explicit use of a storage specifier is prohibited.

    extern "C" int i; // not a definition
    
    int main() {
        i = 1; // error, no definition
    }
    
    extern "C" static void g(); // error
    

    As an example of where this difference matters, consider a header containing the following:

    extern "C" int a;
    extern "C" double b;
    extern "C" char c;
    

    Someone might be tempted to change this to:

    extern "C" {
        int a;
        double b;
        char c;
    }
    

    But that would be incorrect because that converts the declarations into definitions. Instead the correct code using extern "C" {} is:

    extern "C" {
        extern int a;
        extern double b;
        extern char c;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Objective-C NSMutableArray mutated while being enumerated? I use this code to remove
Possible Duplicate: Getting exception as “Collection was mutated while being enumerated” This question is
I'm looking for a language that, while being flexible and very light on memory
I'm trying to center a page on any resolution while still being able to
my question is pretty simple: can PHP and Java communicate, while PHP being the
Is a SSAS 2008 cube available to be queried while it's being rebuilt? If
Is there any way to make the form semi-transparent while it is being moved
I´m looking for a possibillity to prevent all functions from being executet while an
While designing a new WPF application I noticed exceptions not being thrown during data
While enterting password inside EditText view, Characters are being shown and after some delay

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.