Tick Separators

No, a tick separator isn’t something you use on your dog during the summer. Instead, you find it in the upcoming C23 standard. A tick separator helps visually split up a long number, making it easier to read your code.

The tick separator may be available for your compiler. It depends on the implementation and, as mentioned in last week’s Lesson, using the -std=c2x switch when compiling may activate this new feature.

Here’s an example:

int x = 0xff'ff'ff'ff;

The tick has no effect on output or processing; it’s for the programmer’s eyeballs. Above you see hex value 0xffffffff, but the ticks allow you to set groupings, which makes the value more readable. Seeing how the C23 standard allows for binary digit representation, the tick feature greatly helps when coding long, complex values:

int x = 0b1111'1111'1111'1111;

The C23 0b prefix allows binary values to be specified. The tick separators prevent your brain from doing a core dump.

The following code uses the tick separators as a demonstration. Try building it in the compiler’s native mode first to see whether it chokes.

2022_12_17-Lesson.c

#include <stdio.h>

int main()
{
    printf("%d\n",0xff'ff'ff'ff);    /* c23 ticks */

    return(0);
}

Here’s what I saw when using clang to build in its default configuration in macOS:

1217.c:5:20: error: expected ')'
printf("%d\n",0xff'ff'ff'ff); /* c23 ticks */
^
1217.c:5:8: note: to match this '('
printf("%d\n",0xff'ff'ff'ff); /* c23 ticks */
^
1217.c:5:26: warning: missing terminating ' character [-Winvalid-pp-token]
printf("%d\n",0xff'ff'ff'ff); /* c23 ticks */
^
1 warning and 1 error generated.

But when I add the -std=c2x switch, the code builds. Here’s the output:

-1

I won’t be using these separators for code on this blog nor will I use the binary data format until the C23 standard is fully implemented by default. Until then, consider these tidbits I’m writing about in this and future Lessons as more of a sneak preview of what the bold new C23 standard has to offer.

Leave a Reply