https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99720
Bug ID: 99720
Summary: Feature Request: Better errors for C++ features when
compiling C (pass by reference)
Product: gcc
Version: 9.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: cameron at tacklind dot com
Target Milestone: ---
I'm embarrassed that I spent so long on this issue, to the point that I thought
it was worth writing this issue in the hope that it might save someone the same
trouble. If this is inappropriate (or already address), my apologies.
I normally work in the C++ world for simple embedded programming, mostly just
with a subset of the language features. I love the sugar. The old "C" way of
doing things has always bugged me. I'm thinking of basic features like
overloading function.
Now I'm working on a project that has a lot of legacy C that's too much work to
convert to C++.
In implementing a simple function, without thinking, I used a reference (`void
foo(int&i);`) to pass a variable to a function (not a plain pointer). The
astute among you will remember that passing by reference is a C++ feature that
simply does not exist in C.
Error message:
> test.c:1:13: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
It took me most of a day to realize I was trying to use a feature that simply
doesn't exist in C (lots of other #define macros that contributed to my
confusion). It feels like this error message should be easy enough to improve.
With how often C and C++ get conflated, it seems prudent to me to ensure that
accidentally using C++ features in a C compiler would generate warnings or
errors that point towards these possible mistake explicitly.