From: utzoo!decvax!harpo!floyd!whuxlb!eisx!npoiv!houxm!ihnp4!ihnet!tjr Newsgroups: net.unix-wizards Title: BUG(feature) in C-compiler Article-I.D.: ihnet.109 Posted: Fri Apr 29 13:08:06 1983 Received: Sat Apr 30 06:19:11 1983 Beware of an inconsistency in the UNIX 4.0 (etc.) C-compiler and the basic reference manual for the C language: sizeof(object) is NOT "semantically an integer constant" [Kernighan and Ritchie, "The C Programming Language", p188]. sizeof(object) appears to be an unsigned integer. This is reasonable (especially on 16-bit machines), but can cause problems: In UNIX 5.0 message routines, msgrcv returns the number of bytes in the received message, or -1 to indicate an error. This does NOT work: if(msgrcv(...) >= sizeof(struct msg)) handle_message(); If msgrcv() detects an error (e.g. no message to read), its return-value of -1 is converted to unsigned int before the comparison, which will then always succeed! This works: if(msgrcv(...) >= (int)sizeof(struct msg)) handle_message(); Tom Roberts ihnet!tjr