Re: Difference between variables and functions
From: Barry Margolin (barmar_at_alum.mit.edu)
Date: 08/30/05
- Previous message: John Bokma: "Re: Jargons of Info Tech industry"
- In reply to: Ulrich Hobelmann: "Re: Difference between variables and functions"
- Next in thread: Eric Sosman: "Re: Difference between variables and functions"
- Reply: Eric Sosman: "Re: Difference between variables and functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 29 Aug 2005 23:49:01 -0400
In article <3nfsn0F1a6vtU2@individual.net>,
Ulrich Hobelmann <u.hobelmann@web.de> wrote:
> Barry Margolin wrote:
> > In article <3nem0nF15bjvU1@individual.net>,
> > Ulrich Hobelmann <u.hobelmann@web.de> wrote:
> >
> >> But C has first class functions, so you can store functions in variables
> >> and use them as parameters or return them from functions. So I'd say
> >> that calling the int variable "read" with three parameters should be
> >> valid C, just not meaningful.
> >
> > The only variables that can be used this way are those of type pointer
> > to function. Since the variable "read" is not of this type, it's not
> > valid to use it in a function call context.
>
> Wow, I've never experienced C being that anal about types (except when
> it doesn't know the size of a struct that it needs for allocation). I
> assumed that it's all just memory addresses underneath, with some loose
> checking on top.
The analness is implementation-dependent. The language specification
says that calling a non-function has undefined consequences, which means
implementations can do anything. So some implementations with minimal
type checking will allow it through (and hopefully you'll get a
segmentation violation or something like that at runtime), while others
will do the additional checking and report the error at compile time.
Sounds like the OP was using one of the latter types of compilers.
In general, over the years C compilers have gotten a bit better at this
type of thing. In the early days of C, computers didn't have much
memory and the compilers were deliberately kept simple. Now disk and
memory are cheap, and bugs that could have been detected at compile time
can result in security holes, so it's more common to do as much checking
as the language allows.
-- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me ***
- Previous message: John Bokma: "Re: Jargons of Info Tech industry"
- In reply to: Ulrich Hobelmann: "Re: Difference between variables and functions"
- Next in thread: Eric Sosman: "Re: Difference between variables and functions"
- Reply: Eric Sosman: "Re: Difference between variables and functions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|