c - How is the validity of pointer comparisons within an array ensured? -


the c standard guarantees validity of pointer comparison when both point elements of same array, how typically ensured in system?

the compiler might let choose between signed , unsigned pointers. compiler generating assembly comparison. compiler not allocate memory. example, if compile signed pointers, how compiler know runtime won't allocate block array spans signed overflow break?

the compiler might let choose between signed , unsigned pointers. compiler generating assembly comparison. compiler not allocate memory. example, if compile signed pointers, how compiler know runtime won't allocate block array spans signed overflow break?

in other words, how typical implementation ensure no user data spans address 0x80000000 or 0x00000000. well, on popular desktop operating systems, guarantee free, because 0x00000000 in kernel space (inaccessible userspace programs) , 0x80000000 is... well, don't know 32-bit machines anymore. on 64-bit machine, 0x8000000000000000 literally in middle of — typical 64-bit oses don't map anything @ all in gigantic range between 0x0000ffffffffffff , 0xffff000000000000 (source). if have tons of resources, it's no problem @ leave few billion bytes unused. (massive understatement alert!)

now, if you're programming on bare metal, might not guaranteed &a[7] < &a[8]. particularly true if you're programming on risc target such powerpc or v800 , taking advantage of "small data area" located around address 0x0000 (which quick access because loading addresses doesn't require indirection through register). in situation, you're encouraging compiler split variable across 0x0000 boundary (and worse, allow &v == null true), in exchange valuable optimization.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -