public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* Question: C Standad/GCC Extension for How To Assign Binary Number to Unsigned
@ 2021-01-03 21:59 John L. Males
  2021-01-04  9:41 ` David Brown
  0 siblings, 1 reply; 3+ messages in thread
From: John L. Males @ 2021-01-03 21:59 UTC (permalink / raw)
  To: gcc-help

[-- Attachment #1: Type: text/plain, Size: 4778 bytes --]

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.

For the purposes of the questions the variable is an uint32_t.

1) What is the way to assign a bit value to variable?

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

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.


John L. Males
Toronto, Ontario
Canada
03 January 2021 16:59 -0500 EST


================================================================

2021-01-03 21:44:47+0000-UTC Time: 1609710287 PC/System time

 3 Jan 21:44:47 ntpdate[24715]: ntpdate 4.2.8p12-a (1)

3 Jan 21:45:02 ntpdate[26342]: step time server 206.108.0.133
offset -0.003773 sec

FreeBSD 11.4-RELEASE-p3 FreeBSD 11.4-RELEASE-p3 #0: Tue Sep  1
08:22:33 UTC 2020
root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC 

(Work in progress alternative to Linux Kernel of its own right,
 Debian, and
 other Linux based Kernel distributions determined.)

Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz
Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz (1396.86-MHz K8-class
CPU) Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz (1396.86-MHz
K8-class CPU) Intel(R) Core(TM) i3-2367M CPU @ 1.40GHz
(1396.86-MHz K8-class CPU) Intel(R) Core(TM) i3-2367M CPU @
1.40GHz (1396.86-MHz K8-class CPU) Intel(R) Core(TM) i3-2367M
CPU @ 1.40GHz (1396.86-MHz K8-class CPU)

dev.cpu.0.temperature: 85.0C
dev.cpu.1.temperature: 84.0C
dev.cpu.2.temperature: 82.0C
dev.cpu.3.temperature: 82.0C
hw.acpi.thermal.tz0.temperature: 86.1C

vmstat -s:

597793835 cpu context switches
2381693672 device interrupts
122855844 software interrupts
579726032 traps
3573528025 system calls
       27 kernel threads created
   161713  fork() calls
    20352 vfork() calls
     1388 rfork() calls
 12978505 swap pager pageins
 45899170 swap pager pages paged in
  8419303 swap pager pageouts
 58908198 swap pager pages paged out
   831874 vnode pager pageins
  6078199 vnode pager pages paged in
     2920 vnode pager pageouts
     3047 vnode pager pages paged out
    17519 page daemon wakeups
1971151967 pages examined by the page daemon
     2833 clean page reclamation shortfalls
1188069623 pages reactivated by the page daemon
 11764870 copy-on-write faults
     9107 copy-on-write optimized faults
4009265072 zero fill pages zeroed
   171247 zero fill pages prezeroed
 13105889 intransit blocking page faults
812286449 total VM faults taken
 12671361 page faults requiring I/O
        0 pages affected by kernel thread creation
  8281017 pages affected by  fork()
   720292 pages affected by vfork()
    69400 pages affected by rfork()
507838062 pages freed
1046794713 pages freed by daemon
356505942 pages freed by exiting processes
  1421501 pages active
  1453434 pages inactive
    74498 pages in the laundry queue
   644990 pages wired down
   458342 pages free
     4096 bytes per page
1237090115 total name lookups
          cache hits (82% pos + 4% neg) system 0% per-directory
          deletions 0%, falsehits 0%, toolong 0%

Boot time : 1605600247

procs     memory        page                    disks
faults        cpu0     cpu1     cpu2     cpu3 r b w     avm
fre  flt  re  pi  po    fr   sr ad0 pa0   in    sy    cs us sy
id us sy id us sy id us sy id 2 0 23 115566184 1833220   198
289   3   2   124  480   0   0  579   869   145 29  7 64 30  6
64 28  7 64 29  7 64

memory info:

real memory  = 17179869184 (16384 MB)
avail memory = 16495013888 (15730 MB)

last pid: 35482;  load averages:  1.85,  2.59,  2.69  up
47+13:40:56    21:45:03 105 processes: 2 running, 102 sleeping,
1 zombie

Mem: 5553M Active, 5678M Inact, 291M Laundry, 2520M Wired,
1018M Buf, 1789M Free Swap: 48G Total, 7949M Used, 40G Free,
16% Inuse

hw.physmem: 17053859840
hw.usermem: 14411845632
hw.realmem: 17179869184

             total       used       free     shared
buffers     cached Mem:      16210872    8563920
7646952          0          0          0 Swap:     50331644
8139880   42191764

swapinfo:

Device          1K-blocks     Used    Avail Capacity
/dev/ada0s1b     50331644  8139880 42191764    16%

vmstat:

procs     memory        page                    disks
faults         cpu r b w     avm     fre  flt  re  pi  po
fr   sr ad0 pa0   in    sy    cs us sy id 2 0 23 115566184
1833024   198 289   3   2   124  480   0   0  579   869   145
29  7 64


[-- Attachment #2: Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question: C Standad/GCC Extension for How To Assign Binary Number to Unsigned
  2021-01-03 21:59 Question: C Standad/GCC Extension for How To Assign Binary Number to Unsigned John L. Males
@ 2021-01-04  9:41 ` David Brown
  2021-01-04  9:41   ` David Brown
  0 siblings, 1 reply; 3+ messages in thread
From: David Brown @ 2021-01-04  9:41 UTC (permalink / raw)
  To: jlmales, gcc-help

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?)


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Question: C Standad/GCC Extension for How To Assign Binary Number to Unsigned
  2021-01-04  9:41 ` David Brown
@ 2021-01-04  9:41   ` David Brown
  0 siblings, 0 replies; 3+ messages in thread
From: David Brown @ 2021-01-04  9:41 UTC (permalink / raw)
  To: gcc-help

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?)



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-04  9:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-03 21:59 Question: C Standad/GCC Extension for How To Assign Binary Number to Unsigned John L. Males
2021-01-04  9:41 ` David Brown
2021-01-04  9:41   ` David Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).