XPost: comp.os.linux.advocacy   
   From: invalid@invalid.invalid   
      
   Charlie Gibbs writes:   
   > On 2025-12-21, Stéphane CARPENTIER wrote:   
   >> No. There are always defaults, there is no way around, a variable   
   >> must have a default value. That doesn't mean that lot of people with   
   >> agree to chose the same defaults. That's the difference between   
   >> convention and default.   
   >   
   > If the variable is uninitialized, the default might be undefined.   
      
   In C it doesn’t have to have a coherent default at all. Consider:   
      
    int f(void) {   
    int x;   
    return x-x;   
    }   
      
   You might think that should always return 0 since (at least on   
   relatively normal platforms like x86) any integer subtracted from itself   
   always yields 0.   
      
   With GCC that’s what you get:   
      
    f:   
    xor eax, eax   
    ret   
      
   Compiler explorer link: https://godbolt.org/z/nshWTG96G   
      
      
   However Clang exploits the freedom the language specification gives it   
   to return whatever is lying around in the eax register:   
      
    f:   
    ret   
      
   Compiler explorer: https://godbolt.org/z/xfv5zzxM1   
      
   (It’s exploiting the undefined behavior rules.)   
      
   --   
   https://www.greenend.org.uk/rjk/   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|