Option to accept double colon ::

Started by BFG10K, April 08, 2025, 12:29:48 PM

Previous topic - Next topic

BFG10K

One of the few things I miss from C++ is the scope resolution operator :: which makes it really easy to distinguish between variable names and namespaces.

Under the hood all it needs to be is a plain C underscore, but this doesn't work (invalid identifier):

#define :: _
Or perhaps just a compiler extension convert :: to _ included with the /Zx switch.

John Z

Hi BFG10K.

Fortunately this is not C++  :)

The best way to accommodate :: is to use the the replace feature, only takes one
addition step one time if the sources initially contain the ::


John Z

Quin

Giving this feature request a +1. The only use case I see for this in C is, for example, accessing a global variable with the same name as a local. No need for actual namespaces, classes, or any of the other features C++ tacks on that are cool but frankly scare me as someone who likes knowing exactly what my code is doing ;)
int a = 128;
int main() {
    int a = 256;
    int b = ::a; // 128
}
Use the assembly, Luke.

Pelle

Again, this is a C compiler. If you want C++ features you should use a C++ compiler.
/Pelle

Quin

Quote from: Pelle on April 28, 2025, 11:31:00 AMAgain, this is a C compiler. If you want C++ features you should use a C++ compiler.
To be fair, weren't optional arguments originally a C++ feature too? I for my part see nothing wrong with adding enhancements to the C language as Pelles extensions, even if they are rooted in C++, but it is your compiler and I respect your choice :)
Use the assembly, Luke.

Pelle

Quote from: Quin on April 28, 2025, 11:59:21 AMTo be fair, weren't optional arguments originally a C++ feature too?
Yes, optional arguments are from C++ and was the first extension added to Pelles C (a long time ago). I have regretted this extension for many years (it was a fairly small change from the start, but has grown over the years along with the compiler). It's too late to deprecate and remove it.

I'm not a fan of language extensions in general: they tend to lock you into a specific compiler. I have no interest in a full C++ compiler, and any kind of subset will most likely be the wrong one.
These days I can accept things like GNU C extensions, but a completely different language like C++ should really be handled by a completely different compiler.
/Pelle