3

I have been able to use the digit-separator ' in my C projects thus far. They have all been compiled with the MSVC compiler with no problems.

I have just changed to using the GCC compiler instead, which does not allow these digit-separators and throws an error, when I use them. I assume the reason is because, Visual Studio uses the same compiler for C and C++, and in C++14 (I believe), ' digit separators are allowed.

If this is the case, is there then a digit separator usable in GCC? Those separators really help out a lot, when working with 64 bit register values in binary...

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
oPolo
  • 516
  • 3
  • 14
  • 1
    @CarlNorum - This is a completely different question. – Vilx- Jun 26 '16 at 15:18
  • Do you mean separator in printf or separator in number literals? – Krzysztof Krasoń Jun 26 '16 at 15:19
  • @krzyk - Everything points to number literals. – Vilx- Jun 26 '16 at 15:19
  • @CarlNorum how did you know OP is asking about ___only___ `printf()`? – Sourav Ghosh Jun 26 '16 at 15:20
  • Looks like it - sorry, totally misunderstood. If you want C++ features, compile as C++. – Carl Norum Jun 26 '16 at 15:21
  • 1
    Sorry for not being clear. I was talking about separators in number literals (i.e. during assignments). Good idea just compiling it as C++. I guess I will have to, if there is no separator in C. – oPolo Jun 26 '16 at 15:26
  • @oPolo : Since you have conceded that the question is unclear, you should edit to make it clear. I suggest that you include a code fragment example that works in Visual Studio but not GCC - that would make it very clear and you could remove much of the *unclear* text; making the question much snappier and more likely to then get a fast answer and less comment or down-votes. The whole concept of digit separators in literal constants is relatively new to C++, and I imagine many are confused by your question - I had to look it up myself. – Clifford Jun 26 '16 at 16:36

2 Answers2

3

It's defined in n2626, thus, you can use this feature straightly with --std=c2x(for gcc/clang) currently.

poly000
  • 31
  • 5
1

You should use -std=c++1y gcc/g++ option (and have the file named like a C++ file, e.g. cpp/cxx extension) to use ' in number literals.

Krzysztof Krasoń
  • 26,515
  • 16
  • 89
  • 115
  • 3
    -1. Question is asking for a digit separator in C, not C++. Furthermore, C23 will be [introducing `'` as a digit separator](https://thephd.dev/c-the-improvements-june-september-virtual-c-meeting). – AMDG Sep 09 '21 at 21:15