Re: Question: C Standad/GCC Extension for How To Assign Binary Number to Unsigned

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 03/01/2021 22:59, John L. Males via Gcc-help wrote:
> Hello,
> 
> My question is not a need for programming assistance.  My
> question is to understand what the standard is for C with
> respect to my questions.  I have discovered a possible issue,
> but want to ask questions first of expected C standard with
> regards to my questions and if there are any related GCC
> extensions to the questions.
> 

I don't really think this is the best place to ask about C standards,
but I'll try to give you some pointers.  If you think there are issues
about gcc's standards compliance, then of course this is a good starting
point for discussing them.


For details about the C (and C++) standards, I recommend this site:

<https://en.cppreference.com/w/>

It covers just about everything that the standards themselves cover, but
is a good deal easier to navigate and read.

>From this you can see:

<https://en.cppreference.com/w/c/language/integer_constant>

Binary literals (such as 0b01001011) are planned for the future C23
standard, but are not included in any current C standard.  (From the
matching C++ page you can see they were standardised in C++14, along
with optional separators such as 0b0100'1011.)


For details about gcc, the gcc manual is available online for a range of
versions:

<https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/Binary-constants.html>


There are also many options in gcc for picking different standards -
both "real" C standards and gcc extended "standards":

<https://gcc.gnu.org/onlinedocs/gcc-9.3.0/gcc/C-Dialect-Options.html>


> For the purposes of the questions the variable is an uint32_t.
> 
> 1) What is the way to assign a bit value to variable?

There are /many/ ways to do this - this is a basic C question, not a gcc
question.

> 
> 2) What is the format specifier to print a bit value with?

printf format specifiers are part of the C standard:

<https://en.cppreference.com/w/c/io/fprintf>

Different implementations of printf can have extensions with other
format specifiers, but that is up to the implementation of the library,
not the compiler.  gcc is a compiler, not a complete toolchain - it has
no printf.  So if you are using a library on a POSIX system, you'll have
the POSIX extensions to printf documented here:

<https://pubs.opengroup.org/onlinepubs/9699919799/functions/fprintf.html>

Maybe there will be more - it depends on the library.

But I don't know of any printf implementation that supports printing
binary numbers directly.


> 
> 3) What will (2) print like? 
> 
> To be clear these questions are not abut programming
> assistance, but what is the C standard and/or GCC extension.
> 
> 

(Why did you include piles of data about your system?  Did you think the
C standards depend on the temperature of your cpu?)




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux