123 questions
4
votes
2
answers
389
views
In C, is it true that PRId64 is defined if-and-only-if int64_t is available?
I want to portably work with 64-bit signed types in C. However - I know that int64_t is not guaranteed to be defined. I can use some preprocessor magic in my build system generation (e.g. CMake's ...
1
vote
3
answers
123
views
C standard difference between int_least32_t and long
I was wondering, what is the difference between int_least32_t and long, since according to the standard, long has to be at least 32 bits wide and int_least32_t should, according to the standard, also ...
0
votes
2
answers
157
views
can 'fast' type prevent conversion from int to uint?
Consider the following program:
#include <stdio.h>
#include <stdint.h>
int main()
{
uint16_t result;
uint16_t ui = 1;
int16_t si = -1;
result = si * ui;
...
0
votes
3
answers
194
views
What does *((uint32_t)foo) return
Looking at the code:
#include <stdio.h>
#include <stdint.h>
int main() {
char foo[512]={};
printf("%d", *((uint32_t*)foo));
return 0;
}
I'm having hard time ...
0
votes
2
answers
146
views
How using stdint.h has advantage of portability?
I read that stdint.h is used for portability, but I'm confused.
If I wrote a program on a 32-bit system, uint32_t (unsigned int) is 4-bytes.
But when this program is run on 16-bit system, int is ...
0
votes
0
answers
235
views
Are there any platforms that define fixed-width types from stdint.h with bits other than 8, 16, 32 or 64?
The header file <stdint.h> usually provides typedefs and macro constants for integers of 8, 16, 32 and 64 bit width.
The standard also allows any N-bit type to be specified by using identifiers ...
2
votes
3
answers
234
views
What is the difference between using INTXX_C macros and performing type cast to literals?
For example this code is broken (I've just fixed it in actual code..).
uint64_t a = 1 << 60
It can be fixed as,
uint64_t a = (uint64_t)1 << 60
but then this passed my brain.
uint64_t a = ...
1
vote
2
answers
415
views
Is this a bug in glibc printf?
Using stdint.h from glibc (gcc SUSE Linux version 9.2.1, Intel Core I7 processor) I came across a most strange behaviour when printing INT32_MIN directly:
#include <stdio.h>
#include <stdint....
2
votes
1
answer
94
views
Is it possible to determine at compile time whether an implementation provides exact-width integer types? [duplicate]
Is it possible to determine at compile time whether an implementation provides exact-width integer types? Sample code (wanted):
#include <stdint.h>
#if HAS_EXACT_WIDTH_INTEGER_TYPES
uint32_t ...
3
votes
1
answer
3k
views
Legal to initialize uint8_t array with string literal?
Is it OK to initialize a uint8_t array from a string literal? Does it work as expected or does it mangle some bytes due to signed-unsigned conversion? (I want it to just stuff the literal's bits in ...
0
votes
2
answers
234
views
Searching elements in an array
I want to search the index of the element in array days[] of uint8_t type which has next-to-next elements of 0x2 and 0x3 using a variable of type uint16_t and print the index value of the element '0x2'...
-1
votes
1
answer
885
views
Passing uint32_t array to Python using Python.h
I am trying to construct a module for python in C. The module has several lines and methods, but one of the most important is to pass, efficiently, the integer representation of the concatenation of a ...
4
votes
3
answers
1k
views
Why does stdatomic.h contain atomic_uint_least16_t and atomic_uint_fast16_t but not atomic_uint16_t?
stdatomic.h appears to contain atomic_uint_least16_t and atomic_uint_fast16_t, which are _Atomic versions of the stdint.h types uint_least16_t and uint_fast16_t, but it does not contain ...
3
votes
1
answer
360
views
How do I find the width of a uint_fast32_t
I'd like to be able to portably fprintf() a uint_fast32_t as defined in stdint.h with all leading zeroes. For instance if my platform defined uint_fast32_t as a 64-bit unsigned integer, I would want ...
7
votes
3
answers
5k
views
Casting uint32_t to int32_t and comparing them afterwards
I'm having trouble understanding how does comparing two ints, where one is unsigned int32 and the other one signed int32 work.
Let's consider this simple program:
#include <stdint.h>
int main(...
3
votes
1
answer
21k
views
Defining global constants in C
How can I define a global constant in C?
I was told to do some thing like this
in header.h
const u32 g_my_const;
in code.c
#include "header.h"
const u32 g_my_const= 10U;
But I get a compilation ...
1
vote
1
answer
322
views
Can't convert a uint64_t to a double properly. What am I missing?
To give some background, I'm coding the JVM for Java 8 in C, and I'm trying to print the Double value located in the Constant Pool.
I have two variables uint32_t that represent the high and low value ...
0
votes
1
answer
318
views
Is it possible for int_least16_t to be an alias for int rather than short?
From the C99 standard, I can see that int_least16_t is guaranteed to have a width of at least 16 bits.
7.18.1.2 Minimum-width integer types
...
The typedef name uint_leastN_t designates an ...
0
votes
1
answer
46
views
How to configure Fedora 29 to use ruby 'number-theory' gem?
So basically RubyNumberTheory require the NArray gem, and it seems it requires some native compilation tools and probably some additional configuration. So on a Fedora 29, here is what was tried
$ ...
0
votes
2
answers
55
views
Base and inherited objects to wrap stdint variables in C++
I am refactoring some C++ code for an AVR project that uses Sloeber (Arduino plugin for Eclipse). The project has many "settings" variables that are stored in EEPROM, have upper and lower limits, ...
-1
votes
1
answer
335
views
Why is int_fast16_t 64 bits on a 64-bit system?
I looked inside the header file <stdint.h> on my implementation. I see the following:
typedef long int int_fast16_t;
typedef long int int_fast32_t;
typedef long int int_fast64_t;
I have a 64-...
3
votes
1
answer
3k
views
Why is size_t in stddef and not stdint?
I'm just wondering why things like uintptr_t are in stdint.h, but other types like size_t are in stddef.h? Is there logic behind these headers?
0
votes
3
answers
690
views
In embedded MCU application is it better to use uint_fast16_t or size_t in for loops?
I would like to write portable code for applications that will run on different MCUs (16-bits, 32-bits or 64-bits base).
MSP-430
nRF52 (32-bits)
PIC (16-bits)
C51 (8-bits)
Let's consider this snippet: ...
0
votes
1
answer
4k
views
AARCH64 gcc #include <stdint.h> fails
I am trying to compile some kernel code for a raspberry pi 3 from a x86 computer using the aarch64 cross compiler in one of my source files I require stdint.h however when I try to compile it fails ...
4
votes
1
answer
1k
views
C: Is there something wrong with declaring byte arrays as uint8_t?
I'm working on a small networking application that uses byte arrays. Traditionally these would be declared with something like char buf[] = ....
This seems to be how it is (still?) done in most ...