[Stanford GraphBase]

Observação técnica

No módulo GB_GRAPH do SGB, p.287, Knuth adverte:

Important Note:  Programs of the Stanford GraphBase implicitly assume that all memory allocated by calloc comes from a single underlying memory array. Therefore pointer values are compared to each other in many places, even when the objects pointed to have been allocated at different times. Strictly speaking, this liberal use of pointer comparisons fails to conform to the restrictions of ANSI Standard C, when the comparison involves a less-than or greater-than relation. Users whose system supports only the strict standard will need to make several dozen changes.

A nota aparece também, com redação ligeiramente diferente, no arquivo README da distribuição do SGB:

Important note: The Stanford GraphBase programs do not obey the ANSI C standard restriction on comparison of pointers. In fact, the author (Knuth) confesses to being unaware until recently that such a restriction was part of the standard; he wrote the code under the assumption that pointers were essentially machine addresses. No problem occurs with respect to  ==  and  !=  comparison, but the code sometimes has a loop like  for (p = hi; p >= lo; p--)  where  lo  is the base address of a dynamically allocated array. Strictly speaking,  lo-1  is undefined. In other places (e.g., sections 23 and 26 of GB_SAVE) we explicitly test if one pointer is less than another; this code effectively sorts a set of pointers of unknown origin by magnitude, so it assumes that  <  defines a total ordering on pointers. In GB_GATES section 2 we cast a pointer to unsigned long and test whether the result is  <= 1;  conversely, the constant 1 is read as a pointer via a union type in GB_SAVE section 10.

None of this is likely to cause any trouble unless your environment has segmented architecture and 16-bit offsets within each segment. If you do have such a system, your best bet is probably to get one of the free and excellent ports of the GCC compiler. For example, DJ Delorie has succeeded in porting GCC to the MSDOS environment. Alternatively, a set of change files appears on directory  sgb/ANSI.

Felizmente, isso não parece ser um problema para o compilador gcc.

 


Last modified: Mon Jun 8 09:41:33 BRT 2015