0

I was just preparing small codes showing C++ properties. In the following code I use 'linux' variable name and get this error.

#include <cstdio>
#include <cstdlib>

int main(){
    int linux = 19;
    int& debian = linux;
    debian = 90;
    printf("%i\n",linux);
}

which gets:

(base) philo@PL627RC:~/cppTutorials$ g++ references.cpp -o reference
references.cpp: In function ‘int main()’:
references.cpp:5:13: error: expected unqualified-id before numeric constant
5 |         int linux = 19;
  |             ^~~~~
references.cpp:6:23: error: cannot bind non-const lvalue reference of type ‘int&’ to 
 an rvalue of type ‘int’
6 |         int& debian = linux;

This small code works for any other variable name including 'linu' etc. What does this error refers to? Can anybody explain. Thanks.

Sammitch
  • 30,782
  • 7
  • 50
  • 77
  • The linked question explains the issue, but is focused on C. For C++ you should of course use e.g. `-std=c++20` or some other valid C++ version instead of e.g. `-std=c11`. – user17732522 May 05 '22 at 21:33
  • For future reference: the [pre-defined Compiler Macros](https://sourceforge.net/p/predef/wiki/Home/) page is useful reading. – Dúthomhas May 05 '22 at 21:39
  • It's strange though, that this macro doesn't follow the standards prefixing conventions with `__` for compiler implementation details as usual? @fred – πάντα ῥεῖ May 05 '22 at 21:57
  • 1
    @πάνταῥεῖ: It is. I find I only get it using dialect options with GNU extensions, though, such as `-std=gnu++17`. – Fred Larson May 06 '22 at 13:09

0 Answers0