Not sure if I’m tripping right now… but there does not seem to be one right? Still new to C so I might miss something super obvious. All my searches on the web result in just examples using shift operators to recreate a roll operator.

Book is in German but I hope the example is clear enough. It basically tells me I can use <<< and >>> to rotate bits in C23 and up.

Using gcc with --std=c23 results in this error during compilation:

error: expected expression before <= token

Code
#include "stdio.h"  

int main(void) {  
    unsigned char C=0x80;  
    C<<<=1;  
    printf("C=%d\n", C);  
    return 0;  
}  

I am also unsure why its written in the example like C<<<=1; I would have expected C<<<1;.

It is not listed in the cppreference and the book even goes on responding to a readers letter who described another problem like the operator in itself actually exists… I’m so confused right now ;(

EDIT: Ok, it does seem to just not exist… thank you @[email protected] for keeping me sane. I have just sent out an email to the authors to ask for their explanation.

  • setsubyou@lemmy.world
    link
    fedilink
    arrow-up
    12
    ·
    6 days ago

    The page linked above says 2025 but everywhere else (book sellers and the publisher) says November 2024. If that’s correct it would have been an LLM available in mid 2024. So llama 3, gpt 4o etc.

    I asked llama 3 on openrouter and it did hallucinate rotation operators, but they were <<=> and nonsense like that.

    But 4o produces the exact thing claimed in the book:

    The C23 standard introduced new bitwise rotation operators: <<< for left rotation and >>> for right rotation. These new operators simplify the process of rotating bits within an integer, which previously required more elaborate expressions.

    I can’t access some other LLMs from the period anymore like old Gemini and Claude models. But I remember 4o being very popular at the time so it would fit.

    It would have been a deliberate use of an LLM too if it was in 2024 because Google AI Overview in search was not available in Germany until March 2025. So they did not just get tricked by that.

    Not sure where the models got it from though. I only found two old proposals for this syntax from 2008 and 2014, and one was for C++. Other languages that have >>> use it for unsigned right shift (Java, C#, JS, …).