home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c      Meh, in C you gotta define EVERYTHING      243,242 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 242,749 of 243,242   
   James Kuyper to highcrew   
   Re: NULL dereference in embedded [was: O   
   03 Jan 26 18:59:44   
   
   From: jameskuyper@alumni.caltech.edu   
      
   On 2026-01-03 18:25, highcrew wrote:   
   > On 1/4/26 12:15 AM, highcrew wrote:   
   >> I have a horrible question now, but that's for a   
   >> separate question...   
   >   
   > And the question is:   
   >   
   > Embedded systems.  Address 0x00000000 is mapped to the flash.   
   > I want to assign a pointer to 0x00000000 and dereference it to   
   > read the first word.   
   > That's UB.   
      
   Actually, that's not necessarily true. A null pointer is not required to   
   refer to the location with an address of 0. An integer constant   
   expression with a value of 0, converted to a pointer type, is guaranteed   
   to be a null pointer, but that pointer need not have a representation   
   that has all bits 0. However, an integer expression that is not a   
   constant expression, if converted to a pointer type, is not required to   
   be a null pointer - it could convert to an entirely different pointer value.   
      
   So an implementation could allow it simply by reserving a pointer to   
   some other location (such as the last position in memory) as the   
   representation of a null pointer.   
      
   > How do I?   
      
   Even on an implementation that uses a pointer representing a machine   
   address of 0 as a null pointer, such code can still work. In the C   
   standard, "undefined behavior" means that the C standard imposes no   
   requirements on the behavior. That doesn't prohibit other sources from   
   imposing requirements. On such a system, it could define the behavior as   
   accessing the flash.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca