Path: utzoo!utgpu!watserv1!watmath!att!linac!pacific.mps.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!sci.ccny.cuny.edu!phri!cmcl2!adm!smoke!gwyn From: gwyn@smoke.brl.mil (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Function pointer casts in ANSI C Message-ID: <14610@smoke.brl.mil> Date: 29 Nov 90 20:29:10 GMT References: <1990Nov29.110114.21565@diku.dk> Organization: U.S. Army Ballistic Research Laboratory, APG, MD. Lines: 28 In article <1990Nov29.110114.21565@diku.dk> thorinn@skinfaxe.diku.dk (Lars Henrik Mathiesen) writes: >My question is: Can a conforming compiler generate a warning for casts >(and arguments) that will ``go wrong'' but not for those that work? A conforming implementation must produce at least one diagnostic for each translation unit that violates a syntax rule or constraint. Diagnostics may be produced under other circumstances, but are not required. In your example, the syntax is presumably correct, so that leaves only the question of whether a constraint is violated. The relevant constraint appears to be in 3.3.2.2 (Function Calls): each argument must be assignment-compatible with the corresponding parameter. This leads us to 3.3.16.1 (Simple Assignment), where the constraints require pointers to compatible types (apart from the qualifiers). That leads to 3.1.2.6 (Compatible Type and Composite Type), which immediately leads to 3.5.4 (Declarators), more specifically 3.5.4.3 (Function Declarators (Including Prototypes)), where inder Semantics we finally find out what is really required: return value and parameters must have compatible types. So, the final constraint to be checked is whether void* and data* are compatible types. This leads us around to 3.5.4.1, which requires that void and data be compatible types. The search ends here, because there is nothing in the standard that says that void is compatible with a structure type. Thus a constraint IS violated, and a diagnostic IS required. The compiler could go ahead and translate the source into object code that might actually work; there is no requirement that a conforming implementation reject programs that generate diagnostics.