Re: C programming question

From: Juan J. (reidrac_at_usebox.net)
Date: 07/06/05

  • Next message: Juan J.: "Re: C programming question"
    To: Matt <mhersant@comcast.net>
    Date: Wed, 06 Jul 2005 18:36:09 +0200
    
    

    El lun, 04-04-2005 a las 11:43 -0700, Matt escribió:
    > [...]
    > Can someone break down these declarations (if that's what they are)? Is
    > this a form of typecasting? Thanks for your help.

    Those are declarations of pointers to functions.

    /* real function */
    void dumb(int a) { return a; }
    ...

    /* here follows a declaration of func pointer */
    int (*func_ptr)(int);
    int a;

    /* assign it */
    func_ptr=dumb;

    /* use it */
    a=func_ptr(123);

    Any good book about C should cover this. Look for OOP in C also, it's
    frequent use pointers to functions + structs to add classes to C.

    regards,

    Juanjo

    -- 
    Desarrollo y sistemas: http://www.usebox.net/
          Página Personal: http://www.usebox.net/jjm/
    _______________________________________________
    freebsd-hackers@freebsd.org mailing list
    http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
    To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org"
    

  • Next message: Juan J.: "Re: C programming question"

    Relevant Pages

    • Re: pointer to incomplete types
      ... function declarations too, as stated in K&R. ... I tend to prefer "int *" ... What it returned seems to me like an array of pointers to int. ...
      (comp.lang.c)
    • Re: range vs precisionC
      ... volatile int a; ... in this case that is volatile. ... and we have declarations like: ... What is needed now, I think, is to realize that subtypes (and all those ad ...
      (comp.lang.c)
    • Re: K&R-Style Function Declarations: Good or Bad?
      ... > short parameters getting promoted to int. ... all pre-ANSI compilers widened char and short ... declarations -- some compilers converted the widened types back to the ...
      (comp.lang.c)
    • Re: Long(er) Factorial
      ... you declare "int num;" after several call statements. ... all declarations must precede all statements in a block. ... The format for printing a long long ...
      (comp.lang.c)
    • Addressing reference to struct in C#
      ... BOOL ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, ... I see variants of declarations: ... static extern int ReadFile (int hFile, ref object lpBuffer, int ... nNumberOfBytesToRead, ref int lpNumberOfBytesRead, ref OVERLAPPED ...
      (microsoft.public.dotnet.framework.interop)