Re: Difference between variables and functions

From: Eric Sosman (eric.sosman_at_sun.com)
Date: 08/29/05


Date: Mon, 29 Aug 2005 11:12:40 -0400


Ulrich Hobelmann wrote:
> Erik Max Francis wrote:
>
>>It's obvious to _you_ what he meant, because understood his intent and
>>could tell from the code sample that he meant to call the function named
>>read. But the compiler cannot do this, and so it shouldn't try, since
>>if it did it would make mistakes and confuse the programmer even
>>further.
>
>
> I agree there.
>
>
>>What if it wasn't a name conflict caused by a misunderstanding
>>of how the language worked, but rather a typo? In that case, second
>>guessing what the programmer meant and calling the function would be
>>exactly the _wrong_ thing to do.
>
>
> But he's calling a variable, so IMHO C should compile an indirect
> function call there.

    Some other language, perhaps, but not C. Attempting
to call an `int' (or a `double' or a `struct gizmo') is a
constraint violation:

        6.5.2.2 Function calls
        Constraints
     1 The expression that denotes the called function
        shall have type pointer to function [...]

A diagnostic is required (5.1.1.3).

-- 
Eric.Sosman@sun.com


Relevant Pages

  • Re: call to malloc with size 0
    ... > That's not always an option, and a good C programmer should be able to ... > work even with outdated tools. ... Your compiler doesn't require you to ... The vast majority of posters with such problems (calling unprototyped functions) ...
    (comp.lang.c)
  • Re: PEP 3107 and stronger typing (note: probably a newbie question)
    ... typing is to provide optimization clues for the compiler. ... the programmer said it's a ... That compiler, I believe, would violate the ISO standard for C (so ... calling it a "C compiler" would be about as correct as calling it a ...
    (comp.lang.python)
  • Re: [EGN] Hoisting Loop Invariants (Was: Re: [EGN] Numerical Accuracy)
    ... compiler out there somewhere that did as you claim. ... > the programmer has this knowledge, then the programmer should not use ... >> string in a loop, regardless of the blatant inefficiency of doing so. ...
    (comp.programming)
  • Re: The Philosophy of Programming?
    ... A compiler is free to ... >>is to allocate on entry to almost any block. ... > int foo{ ... But any programmer who wants to be more than a coder prefers, I think, ...
    (comp.programming)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... what experienced programmers do, ... the compiler doesn't have the free pass to /assume/ that the function ... Nobody has recommended doing all optimization by hand to my knowledge. ... Compiler behavior in optimization simply has no place in a language ...
    (comp.programming)