5

What does following 0x0\1 mean in following code? I find this in an embedded C code:

uint16 size;
...
size += (size & 0x0\1);

It's part of Texas Instruments released code. It compiles in IAR ARM IDE.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
doubleE
  • 1,027
  • 1
  • 12
  • 32
  • 4
    I'm not able to get the code in question to compile. – iikorni Oct 26 '16 at 02:19
  • It's part of TI released code. It compiles in IAR ARM IDE. – doubleE Oct 26 '16 at 02:20
  • Probably just octal 1. But don't ask me why. – deamentiaemundi Oct 26 '16 at 02:26
  • 2
    I'm not able to get it to compile, either (under gcc or clang). gcc complains (and not surprisingly) about "stray ‘\’ in program". This is not portable code. The backslash there has no meaning in portable C. Whatever it means, we can't tell you; you might have to ask TI. – Steve Summit Oct 26 '16 at 02:35
  • Can you compile the code? In that case, maybe you can see if there is a difference in the binary. What if it was a misprint? There is a texas-instruments tag too that might help. – Robert Prévost Oct 26 '16 at 03:25
  • @SteveSummit I think the hope is that someone with specific knowledge of the TI compiler will see the question. I'll admit the odds are against it. – Mark Ransom Oct 26 '16 at 03:40
  • 2
    I suggest using `printf("%d\n", 0x0\1);` to find out what it translates to (most likely, it is equivalent to `1`, but it's non-standard so anything is possible). Then either edit the code to replace it, or ignore it for the future. – Jonathan Leffler Oct 26 '16 at 03:50

1 Answers1

3

Non-portable, implementation dependent, non-standard conforming code. It is anybody's guess what the original author has intended but "probably" means size += size & 0x1. That is: increment size by 1 in case size is odd (that is, least significant bit is 1).

teroi
  • 1,087
  • 10
  • 19