Skip to main content
Filter by
Sorted by
Tagged with
4 votes
1 answer
273 views

The follow derives from the devkitpro 3ds filter audio example though it's not relevant to know exactly how the example works. In short, consider this code: size_t data_size = ...; uint32_t data* = (...
Nil A Curious Programmer's user avatar
4 votes
2 answers
129 views

I have an example of C code with an issue (integer promotions from uint16_t to int, and then cast to uint32_t): #include <stdio.h> #include <stdint.h> int main() { uint16_t x = 48000; ...
alex_why's user avatar
  • 137
4 votes
2 answers
294 views

Hello and thanks for reading, I just came upon a bug in my C program and while I was able to find out the cause of the bug I am having trouble rationalizing the behaviour of the compiler and I could ...
MJLW's user avatar
  • 69
2 votes
2 answers
101 views

I'm writing a C++ logging implementation for an embedded system.The idea is to use templates to declare the message id (type) and enforce the arguments. There are constraints that the code I'm writing ...
Sarge324's user avatar
0 votes
2 answers
114 views

I read the c documentation but I couldn't understand it. Could you please answer my questions(Maybe my English is not good.) I have two codes and two question. Question about first code: Has an ...
İlker Deveci's user avatar
2 votes
0 answers
60 views

I was digging into code of flatbuffers and it does seem to me that there is undefined behavior in the core library. But I just can't believe it is there (and it seems to work in some usecases)... I'd ...
Richard Steidl's user avatar
0 votes
2 answers
182 views

It is discussed in another thread that reading a file with the following code can result in an infinite loop because EOF is an integer outside the range of char and the while condition therefore ...
cdalitz's user avatar
  • 1,371
6 votes
3 answers
151 views

Let's take the following code which we compile for a 32 bit system: typedef unsigned int uint32; typedef unsigned char uint8; ... uint8 y = 0xFF; uint32 x = (y << 24U); y can be promoted to int ...
Sterpu Mihai's user avatar
35 votes
3 answers
2k views

I was helping a student with his assignment and ran into a very gnarly "bug" which I could not explain, and was wondering if I could get help in understanding what exactly is going on. The ...
elialm's user avatar
  • 781
-1 votes
2 answers
200 views

For context, I on a 64-bit (AMD64) little-endian system and am using g++ -std=gnu++23 -O3 -Wall to compile my code, if it makes any difference. The following code snippet all shows some seemingly ...
Mel's user avatar
  • 127
-1 votes
1 answer
172 views

In C#, why can't we add int to long? Why does the compiler need implicit conversion from int to long to perform the operations? Similar for byte to short or short to int: why is an implicit conversion ...
Hathibelagal Praneeth's user avatar
0 votes
1 answer
68 views

I am writing a wrapper to call API functions in a vtable. This is done through a variadic temple, to wrap API functions with an arbitrary number of parameters. I have found that some calls work only ...
haton's user avatar
  • 3
41 votes
4 answers
4k views

I've read cppreference.com's implicit conversion: Integral promotion: prvalues of small integral types (such as char) may be converted to prvalues of larger integral types (such as int). [...] Note ...
LiDa Cute's user avatar
  • 475
10 votes
1 answer
485 views

I wonder why a - b and a + (-b) give the same result but in different types in numpy: import numpy as np minuend = np.array(1, dtype=np.int64) subtrahend = 1 << 63 result_minus = minuend - ...
bers's user avatar
  • 6,309
0 votes
1 answer
67 views

int main(){ int a, b; char *cp; a = 511; cp = &a; b = *cp; *cp = 10; printf("%d %d %d", a,b,*cp); return 0; } The output for the above code is 266 -1 10 ...
JoshuvaBernard's user avatar
0 votes
2 answers
125 views

#include <stdio.h> int main() { unsigned char c = 'a'; c = c + 3; printf("%c ", c); printf("%zu",sizeof(c)); return 0; } Output:d 1 when integer ...
sai praveen's user avatar
3 votes
0 answers
40 views

I'm getting -Wconversion warning in C. conversion from 'int' to 'uint8_t' {aka 'unsigned char'} may change value [-Wconversion] When performing the following operation: uint8_t output_A = 0x00; ...
wzs's user avatar
  • 31
6 votes
0 answers
154 views

Consider an unsigned char v that goes through a series of bit-wise operations with the result stored back to v. Under the hood, it is integer promoted once, undergoes a series of operations, and the ...
Lingxi's user avatar
  • 15.1k
6 votes
2 answers
182 views

For the code: int hi(int); int hi(); int main() { hi(3); } I don't get any compilation errors (calling hi(); without arguments does get a compilation error). I expected that the compiler would ...
arye's user avatar
  • 511
2 votes
3 answers
112 views

I made a reproducible code as below/ #include <stdio.h> int main(void) { long int a = 0x0; a |= (1 << 31); printf("a: 0x%lx\n", a); } I expect 'a' should be ...
Jason Park 's user avatar
0 votes
2 answers
1k views

I have below function to check some count value and update the final count. uint16 final_count = 0U; uint8 count1 = 0U; uint8 count2 = 0U; uint8 count3 = 0U; uint8 count4 = 0U; void test(void) { ...
user2986042's user avatar
  • 1,300
7 votes
3 answers
2k views

uint32_t a = 10; uint16_t b = 0; if (a > b) { printf("a > b\n"); } I was expecting that b would get promoted to int and the compiler would complain about comparing signed and ...
Karthick's user avatar
  • 1,000
-3 votes
2 answers
328 views

In java, the compiler throws an error if you try to assign a double literal to an int variable. However, it allows the assignment of an int literal to variable of type long. double d = 4.0; ...
kaka's user avatar
  • 845
3 votes
1 answer
78 views

I am a bit confused about how default argument promotions effect wchar_t. I understand that char is promoted to int, and therefore I have to supply int as the second parameter of va_arg, otherwise I ...
z32a7ul's user avatar
  • 3,847
0 votes
2 answers
103 views

While writing a program for uni, I noticed that unsigned char byte_to_write_1 = (0xFF << 2) >> 2; ==> 0xFF (wrong) unsigned char byte_to_write_2 = (0xFF << 2); byte_to_write_2 = ...
Seth Rossman's user avatar
-1 votes
1 answer
132 views

I was trying to write an overloaded function to accept both signed and unsigned integers. Following is my code: #include <iostream> void fun(const long long a) { std::cout << "...
Vijaymahantesh Sattigeri's user avatar
22 votes
2 answers
3k views

Consider the following listing: #include <type_traits> #include <cstdint> static_assert(std::is_same_v<decltype(31), int32_t>); static_assert(std::is_same_v<decltype(31u), ...
ivaigult's user avatar
  • 6,807
5 votes
4 answers
718 views

I am learning C, and integer promotion and the term demotion is new to me. I have read in the C Standard (C17) about the C type conversions and the integer promotion, but I don't know how to identify ...
Cblue X's user avatar
  • 353
3 votes
3 answers
237 views

I tried to compare with strlen(string) with -1 but different methods gave different results: char string[] = {"1234"}; int len = strlen(string); int bool; bool = -1 < strlen(string); ...
chaganhu's user avatar
6 votes
3 answers
245 views

I encountered a strange problem, but to make it clear see the code first: #include <stdio.h> #include <stdint.h> int main() { uint8_t a = 0b1000'0000; // -> one leftmost bit ...
timoxd7's user avatar
  • 127
0 votes
1 answer
171 views

I've got a copy of the book "The C Programming Language", and in one of the first chapters it shows a short example of a code that copies characters from stdin to stdout. Here is the code: ...
noname delete's user avatar
1 vote
2 answers
148 views

I am struggling with the realization of a signed long long int variable having the value 1 set in its integer part. Looking at the 16.16 implementation with a signed long int variable it does work ...
kvirk's user avatar
  • 141
-1 votes
1 answer
57 views

What's the Difference between the number as char and the number as int (or any type, which I can make any arithmetic operation using it like double on c++) on memory - Regarding the equivalent number ...
AhmedWaleed9's user avatar
10 votes
2 answers
1k views

struct Type { uint8_t var : 3; }; int main() { struct Type bar; bar.var = 1; uint8_t baz = bar.var << 5; } According to the standard, left shifting more than the width of the ...
Iman Seyed's user avatar
0 votes
1 answer
99 views

int main(){ char a = 5 + (16711935 * 1200); return 0; } Based on the type of integer literals and conversion rules in C, 16711935 is of type int and 1200 is promoted to an int. My question is what ...
Dan's user avatar
  • 3,068
3 votes
3 answers
992 views

Consider the following code: enum ABC : char { a, b, c }; void ff(char c) { cout << "char\n"; } void ff(int i) { cout << "int\n"; } int main() { ff(a)...
CPPL's user avatar
  • 846
0 votes
2 answers
365 views

In C, I understand type conversions, integer promotion, casting, etc. for standard types, but how do the stdint.h types factor into this? For type rankings, the rules state: No two signed integer ...
user1801359's user avatar
0 votes
4 answers
193 views

I have the following code where behavior is not clear to me. Can some one please help how conditional operator evaluate the following code and output ans as 1 #include int main() { bool ...
Sijith's user avatar
  • 4,018
7 votes
1 answer
466 views

I'm currently writing some code for embedded systems (both in c and c++) and in trying to minimize memory use I've noticed that I used a lot of code that relies on integer promotions. For example (to ...
TomK's user avatar
  • 79
4 votes
3 answers
537 views

I bumped into this while writing a program trying to print the constituent byte values of UTF-8 characters. This is the program that I wrote to test the various ~0 operations: #include <stdio.h> ...
Marcus Harrison's user avatar
1 vote
2 answers
149 views

#include <stdio.h> #include <stdlib.h> int main() { unsigned char a=100,b=50; printf("%d & %d = %d\n",a,b,a&b); printf("%d | %d = %d\n",a,b,a|b); printf("...
Lucas's user avatar
  • 25
2 votes
5 answers
8k views

Hey I am kinda new to C and I wanted to ask why this prints out 4 instead of 260? #include <stdio.h> int main() { unsigned char x = 130; x *= 2; printf("%d\n", x); }
Alpha's user avatar
  • 329
2 votes
2 answers
98 views

I am doing the following bitwise shift in Microsoft C++: uint8_t arr[3] = {255, 255, 255}; uint8_t value = (arr[1] << 4) >> 4; The result of these operations confused me quite a bit: ...
Runsheng Ma's user avatar
-1 votes
2 answers
98 views

What is wrong with this code? The answer should be 24 for this question right? int t; vector<int>arr={24,434}; for(int i=arr.size()-1;i>=(arr.size()-2);i--) { t=i; } cout<<...
Himanshu Chand's user avatar
3 votes
3 answers
155 views

Have a look at the example: unsigned char c = 64; /* 0100 0000 */ c = (c << 2 && 512); /* 512: 10 0000 0000 */ If I shift c two times to the left, I should get from 0100 0000 (64) to ...
B0r1's user avatar
  • 490
4 votes
1 answer
299 views

The C11 standard defines the _Bool type (6.2.5.2) as a standard unsigned integer type (6.2.5.6) and as I read the standard, _Bool is then also an arithmetic type (6.2.5.18 via 6.2.5.7 and 6.2.5.17). ...
nielsen's user avatar
  • 8,091
0 votes
1 answer
380 views

I have a huge array of integers and those integers are not greater than 0xFFFF. Therefore I would like save some space and store them as unsigned short. unsigned short addresses[50000 /* big number ...
user3600124's user avatar
-1 votes
3 answers
139 views

I need help solving this problem in my mind, so if anyone had a similar problem it would help me a lot. signed char c=0x10; printf("%x", c<<0x4|c>>0x4); Why output is 101?
LogicNotFound's user avatar
0 votes
3 answers
1k views

Why in second printf when using %d I am not getting -1? #include<stdio.h> int main(){ unsigned int u=-1; unsigned short int y=-1; printf("%d %u\n",u,u); printf("%d ...
Sameer Raj's user avatar
1 vote
3 answers
2k views

Why does the int hum2() function returning a boolean type? Shouldn't the function return the type I defined it as. Like Float function returns float value of Double function returns a double value. #...
Efty Shan Abid's user avatar

1
2 3 4 5 6