Undefined Behavior (UB)
พฤติกรรมที่มาตรฐาน ไม่ได้กำหนดเลย Compiler/OS ทำอะไรก็ได้ (crash, ผลผิด, ทำงานได้, security hole)
ตัวอย่าง: i++ + ++i, u = (u++), dereference null pointer, buffer overflow
Implementation-defined Behavior
มาตรฐานไม่กำหนด แต่ implementation (compiler) ต้องเลือกหนึ่งทางและ document ไว้ รับประกันว่าจะทำอย่างนั้นเสมอ
ตัวอย่าง: ขนาด int, signed right shift behavior, alignment requirements
Unspecified Behavior
มาตรฐานให้ทางเลือกหลายทาง แต่ ไม่บังคับให้ implementation document หรือ guarantee อาจทำต่างกันไปในแต่ละครั้งก็ได้
ตัวอย่าง: ลำดับการ evaluate function arguments, ค่าของ padding bytes ใน struct
สรุป
- UB: ไม่ได้กำหนด - อันตรายที่สุด ต้องหลีกเลี่ยง
- Implementation-defined: กำหนดโดย compiler - ต้อง document - ค่อนข้างปลอดภัยถ้ารู้ behavior
- Unspecified: หลายทางเลือก - ไม่ guarantee - ระวังการพึ่งพา