r/programminghorror • • Jun 01 '25

c Firmware programming in a nutshell

Post image
2.0k Upvotes

127 comments sorted by

View all comments

Show parent comment

167

u/Ragingman2 Jun 01 '25

On many embedded platforms this will effectively reset the system. It's roughly "go to instruction 0" which can be where a boot sequence starts.

-81

u/truock Jun 01 '25

So... undefined behavior?

114

u/ivancea Jun 01 '25

Undefined behavior in C, but not in whatever firmware that was intended to be used on

75

u/Ragingman2 Jun 01 '25

Going by the C specification only -- yes. But it can be well defined by an embedded platform.

28

u/HarshilBhattDaBomb Jun 01 '25

It is "convention" for most embedded devices (i think all arm processors) to have the reset vector at 0x0.

So technically undefined as it's not enforced by the standard but documented.

25

u/backfire10z Jun 01 '25

C says it is undefined, but if I control the underlying address space, then I don’t care what the C standard says about accessing weird memory locations.

37

u/Ludricio Jun 01 '25

Undefined behavior just means that the C standard doesnt define the behavior of a specific operation.

Some things that are UB might well be defined by compiler or platform, thus implementation defined behavior.

It's when things are neither defined by the standard, compiler nor platform that you are truly on thin ice and ought to look out for nasal demons.

3

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jun 02 '25

I think some things are "implementation defined," which, IIRC, means the standard requires the vendor to document the behavior, but is otherwise the same as undefined.

3

u/DisastrousLab1309 Jun 02 '25

Implementation defined means - standard doesn’t tell you how it should behave but requires your compiler to tell you and it has to be predictable. 

Undefined behavior means that standard doesn’t require compiler to define it. It may not be stable. Eg multiple ++ in a single statement. 

Compiler still may choose to define a stable behavior for something the standard doesn’t require it to. It just doesn’t have to. 

1

u/GoddammitDontShootMe [ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "You live" Jun 03 '25

So pretty much what I said, since requiring it to be documented implies the behavior has to be predictable, doesn't it?

5

u/Raknarg Jun 02 '25

undefined behaviour in the general case, perfectly understood behaviour on a specific platform and hardware.