Skip to main content

Questions tagged [undefined-behavior]

3 votes
3 answers
286 views

On occasion, it is very useful to reinterpret raw bytes structured data - ints, floats, etc. Eamples include reading from a mmapped file, reading some sort of in-memory data frame, or other tasks that ...
Alecto's user avatar
  • 571
-1 votes
5 answers
3k views

I happen to have a reason why I might want to dereference a nullptr. Of course when I do, my program crashes, and from what I gather, this is due to the compiler playing it safe and stopping my ...
Anon's user avatar
  • 3,649
1 vote
1 answer
386 views

I just started at a small company and there is a hot-needle-built software for micro controllers written in C which we are now starting to clean up to make it maintainable again. Of course this goes ...
user avatar
61 votes
11 answers
15k views

This Stack Overflow post lists a fairly comprehensive list of situations where the C/C++ language specification declares as to be 'undefined behaviour'. However, I want to understand why other modern ...
Sisir's user avatar
  • 898
-1 votes
1 answer
280 views

What do I pass in for the existing arguments that have no value, undefined or null? Existing function foo(a, b) is called like foo(1) and foo(23, "hi"). After adding a new parameter, it's foo(a, b, ...
Josh's user avatar
  • 175
3 votes
5 answers
2k views

I want to compare sequence numbers (given to this code from elsewhere) that may wrap around. Simply comparing two such values will not handle the case like 0x00000002 being greater than 0xfffffffd, ...
JDługosz's user avatar
  • 598
1 vote
2 answers
1k views

My C++ book says that if I have int anArray[25]; and I try to evaluate anArray[25] = 0; the program will simply overwrite whatever value is stored in the next memory address past the end of the ...
moonman239's user avatar
  • 2,063
2 votes
2 answers
302 views

If there's a bug that triggers undefined behavior in a piece of code, is the undefined behavior consistent each time running it? and changes each time compiling it? For example if you had some C code ...
Vikaton's user avatar
  • 255
10 votes
5 answers
2k views

Some hyper-modern C compilers will infer that if a program will invoke Undefined Behavior when given certain inputs, such inputs will never be received. Consequently, any code which would be ...
supercat's user avatar
  • 8,669
1 vote
3 answers
2k views

I hope this question fits this site. You may know you can't detect undefined behaviour in C using compilers - and some tools (static analysis) can help you detect it. My question is more empirical - I ...
user avatar
4 votes
0 answers
327 views

In a C implementation where int can hold all values of type unsigned short, standard integer promotion rules dictate that given the code: unsigned short x=(USHORT_MAX+1)-3; // Or just -3 x*=x; a ...
supercat's user avatar
  • 8,669
9 votes
5 answers
2k views

Whether in C or C++, I think that this illegal program, whose behavior according to the C or C++ standard is undefined, is interesting: #include <stdio.h> int foo() { int a; const int ...
thb's user avatar
  • 757
18 votes
5 answers
9k views

I was reading this question on SO which discusses some common undefined behavior in C++, and I wondered: does Java also have undefined behaviour? If that is the case, then what are some common causes ...
Eight's user avatar
  • 325
5 votes
2 answers
439 views

Recently I came across a number of undefined features in C, one of them being the following: https://stackoverflow.com/questions/8698048/behaviour-of-non-const-int-pointer-on-a-const-int Could ...
SHOUBHIK BOSE's user avatar
63 votes
13 answers
10k views

C\C++ specifications leave out a large number of behaviors open for compilers to implement in their own way. There are a number of questions that always keep getting asked here about the same and we ...
Alok Save's user avatar
  • 1,138

15 30 50 per page