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 @lime@feddit.nu for keeping me sane. I have just sent out an email to the authors to ask for their explanation.

    • vogi@piefed.socialOP
      link
      fedilink
      English
      arrow-up
      14
      ·
      edit-2
      3 days ago

      Oh wow… :(( I really like the way the book is written and do not want to stop, its so weird though how the authors are so confidently wrong about this one. I think the publisher is reputable as well. For completeness the ISBN is 978-3-367-10440-6

      Thank you for confirming and looking up the draft. At least I am apparently not losing my mind even if it means I cannot trust anything the book tells me now. :/

      No reference, interesting enough it also lists all operators in the index except <<< which gives me the impression they updated it to C23 very quickly just to be able to write it on the cover :(

        • setsubyou@lemmy.world
          link
          fedilink
          arrow-up
          11
          ·
          2 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, …).

        • vogi@piefed.socialOP
          link
          fedilink
          English
          arrow-up
          4
          ·
          2 days ago

          Yea, i thought the same thing. It really feels like they took the old version and gave it to an LLM to update it to C23 which in turn might have picked up an obscure blog post proposing this change or it might have come up with this all on its own. I really don’t think it is the case though both publisher and the authors are reputable. Its just so bizarre, i am really looking forward to hear their answer to my email I sent.

      • lime!@feddit.nu
        link
        fedilink
        arrow-up
        9
        ·
        3 days ago

        weird for such prolific authors too. but honestly, not that big a deal. it was a really unusual thing to talk about, because no other higher-level language that i know of supports bit rotation directly. that means it probably won’t come up again.

      • thingsiplay@lemmy.ml
        link
        fedilink
        arrow-up
        4
        ·
        2 days ago

        Maybe it was planned at some point and the author assumed it will be in the standard? And at the end of the book everything that is not in the standard got removed, but they forgot this part maybe.

  • smol_cat@lemmy.zip
    link
    fedilink
    English
    arrow-up
    7
    ·
    2 days ago

    well, you could do this in C++ if you overloaded the comparison and bitshift operators, as well as adding a macro. something like: (I am typing this on a phone, and haven’t tested it

    #define <<< << _ROTATOR_RIGHT_ARG <
    #define _ROTATOR_RIGHT_ARG _ROTATOR_RIGHT_ARG_T()
    template<typename T> class _ROTATOR_RIGHT_ARG_T {T val};
     auto operator< (_ROTATOR_RIGHT_ARG_T _, auto b) -> _ROTATOR_RIGHT_ARG_T<decltype(b)>{
    return _ROTATOR_RIGHT_ARG_T<decltype(b)>{.val = b};
    }
    

    then overload the bitshift operator in a similar way. the above is simply a proof of concept, should have many improvements, like adding constexpr and using concepts (the C++ feature) to ensure that the arguments are bitshiftable, but this is shit code and I would just use (as a temporary solution)

    auto bitwise_rotate_l(auto a, auto b) ->/* (type shenanigans I can't be bothered to look up)*/{
    return /* bitwise rotate */;
    }
    
    • vogi@piefed.socialOP
      link
      fedilink
      English
      arrow-up
      5
      ·
      3 days ago

      That site is cool! Thank you for sharing.

      Yea, apparently it just does not exist :/ Which is super odd. Just wrote a mail to the authors asking for clarification/correction.

      And thank you for the info regarding <> :) I should have known it by now, I guess old habits die hard.