How to use binary prefix according to C11?

I am currently starting to program microcontrollers using C30(A microchip Cbased compiler GCCfor my devices PIC24), and I turned it on Strict ANSI warningsout of curiosity. Firstly, I didn’t know that in the comments of the C11 comment, for example, // are "wrong", and instead I should use / * blah blah * /, but I was really surprised by this warning for a line of code.

"warning: using non-standard binary prefix"

Line of code:

OSCCONbits.COSC = 0b000;

I looked online on one of the C11 projects (ISO / IEC 9899: 2011) and cannot find anything about binary prefixes in C. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570 .pdf

What is the correct binary notation for C according to C11?

+5
source share
4 answers

C has no binary constants. (Even in C11, they are not supported.)

They were offered as an addition to the C99, but the offer was rejected.

From document document C99:

The proposal to add binary constants was rejected due to lack of precedent and insufficient utility.

You said you use compiler-based gccand gccsupports binary constants: they are a GNU extension for C.

, 0 1, 0b 0b. , (, ).

. gcc :

http://gcc.gnu.org/onlinedocs/gcc/Binary-constants.html

+13

C11 ; , , 6.4.4.1 . C99.

6.6 10 :

.

, , , ; C99.

; . (, , 0b000 0.)

+3

:

  • ANSI C/ "Strict ANSI" C, 1989. "C89".
  • ANSI C/89 1990 , C C, ISO/IEC 9899: 1990, "C90". C89 C90 , .
  • C90 1999 , ISO C. "C99".
  • C99 2011 . "C11".

:

  • C89/C90 //. C99. C11.
  • C.

:

  • Most likely you are compiling code in the C90 compiler with some non-standard extensions.
+2
source

Binary prefixes are not standard. instead, convert them to octal ( 0) or hexadecimal ( 0x), which are only prefixes defined in the standard.

In addition, comments //were introduced in the C99 standard; they are not present in the ANSI C89 standard. This is why your compiler gives you a warning.

+1
source

All Articles