1

If I use clang 3.8.1 to compile:

extern "C" {
int foo(int x) { register int y = x; return y; }
}

int main() { return foo(123); }

I get the warning:

a.cpp:3:18: warning: 'register' storage class specifier is deprecated and incompatible with C++1z [-Wdeprecated-register]
int foo(int x) { register int y = x; return y; }
                 ^~~~~~~~~

... which I really shouldn't be getting this, since the inner function is C code. If I use GCC 6.3.1, even with -Wall, I don't get this warning.

Is this a clang bug or am I doing something wrong?

4
  • That's not related to C! Commented Apr 18, 2017 at 14:15
  • 2
    The code ist still C++ code! extern "C" just specifies the ABI and nameing conventions. (did you even read the warning?) Commented Apr 18, 2017 at 14:16
  • 1
    extern "C" only has effect on linkage of external names - it doesn't' change the compiler to 'C-mode'. Commented Apr 18, 2017 at 14:16
  • either fix it, or compile this part in C - whichever makes sense. Commented Apr 18, 2017 at 14:26

2 Answers 2

8

extern "C" does not mean "compile this code as C". It means "make this function (or functions) callable from C code", which typically means changing name mangling and, sometimes, calling convention.

Sign up to request clarification or add additional context in comments.

3 Comments

Another way to look at it: it means "the name of this function is in C," rather than the body.
@JohnZwinck - it can involve more than the name.
@JohnZwinck: Not exactly. It also implys C calling conventions.
0

Perhaps the error has nothing to do with the extern "C"? It looks like it says, not, "register is incompatible with C" but rather "register is incompatible with C++1z". (I assume C++1x means C++11/14/17.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.