What should be the prototype of this function ? (noonie) - C

This is a discussion on What should be the prototype of this function ? (noonie) - C ; Hello, I have a struct defined thus: typedef struct myStruct { int j; } myStruct; I saw somewhere calls with the following syntax: f1(&*a) What should be the protype of f1 so that it will be correct and so that ...

+ Reply to Thread
Results 1 to 5 of 5

What should be the prototype of this function ? (noonie)

  1. Default What should be the prototype of this function ? (noonie)

    Hello,
    I have a struct defined thus:

    typedef struct myStruct
    {
    int j;
    } myStruct;

    I saw somewhere calls with the following syntax:
    f1(&*a)

    What should be the protype of f1 so that it will be correct and
    so that compilation will succeed ?

    I am talking about two cases:
    In the first, we have the following definition:
    myStruct a;

    in the second, we have
    myStruct* a;

    Is it possible with both case to have a definition of f1() so that
    f1(&*a) will be correct and pass compilation ?

    Any ideas?

    Ian


  2. Default Re: What should be the prototype of this function ? (noonie)

    On 17 Oct, 10:24, "ian...@gmail.com" <ian...@gmail.com> wrote:

    > I have a struct defined thus:
    >
    > typedef struct myStruct
    > {
    > int j;
    >
    > } myStruct;
    >
    > I saw somewhere calls with the following syntax:
    > f1(&*a)
    >
    > What should be the protype of f1 so that it will be correct and
    > so that compilation will succeed ?
    >
    > I am talking about two cases:
    > In the first, we have the following definition:
    > myStruct a;
    >
    > in the second, we have
    > myStruct* a;
    >
    > Is it possible with both case to have a definition of f1() so that
    > f1(&*a) will be correct and pass compilation ?
    >
    > Any ideas?



    this looks like homework to me...


    --
    Nick Keighley




  3. Default Re: What should be the prototype of this function ? (noonie)

    Nick Keighley wrote:
    > On 17 Oct, 10:24, "ian...@gmail.com" <ian...@gmail.com> wrote:
    >
    >> I have a struct defined thus:
    >>
    >> typedef struct myStruct
    >> {
    >> int j;
    >>
    >> } myStruct;
    >>
    >> I saw somewhere calls with the following syntax:
    >> f1(&*a)


    [To the OP] Really? Where? What do you think it will do?

    > this looks like homework to me...


    It looks like bovine excrement to me.

  4. Default Re: What should be the prototype of this function ? (noonie)

    struct name { /* ... */ };

    ret f(struct name *);

    struct name obj1, *obj2, obj3[1], **obj4;
    f(&obj);
    f(obj2);
    f(obj3);
    f(*obj4);

    Etc.

    `&*p' == `&p[0]'


  5. Default Re: What should be the prototype of this function ? (noonie)

    On Wed, 17 Oct 2007 09:24:50 -0000, "ianbrn@gmail.com"
    <ianbrn@gmail.com> wrote:

    >Hello,
    >I have a struct defined thus:
    >
    >typedef struct myStruct
    >{
    > int j;
    >} myStruct;
    >
    >I saw somewhere calls with the following syntax:
    >f1(&*a)


    It would help if we new what a was.

    What do you think the effect of the combined & and * operators is? For
    extra points, would it make a difference if the operators were
    reversed? What is the only possible type the expression &*a (or *&a)
    can have (on those occasions when it is a legal expression)?

    >
    >What should be the protype of f1 so that it will be correct and
    >so that compilation will succeed ?


    The prototype is not the problem.

    >
    >I am talking about two cases:
    >In the first, we have the following definition:
    >myStruct a;


    What happens when you apply the * operator to a struct?

    >
    >in the second, we have
    >myStruct* a;
    >
    >Is it possible with both case to have a definition of f1() so that
    >f1(&*a) will be correct and pass compilation ?


    While passing an incompatible type to a function possibly could be
    "corrected" by changing the prototype, what makes you think a
    prototype can magically correct a syntax error?

    Again, what happens when you apply the * operator to a struct?

    >
    >Any ideas?


    Yes. Make a note of the author who wrote the call to f1. Then make
    sure you never again take anything written by him seriously.


    Remove del for email

+ Reply to Thread

Similar Threads

  1. Re: function prototype
    By Application Development in forum c++
    Replies: 12
    Last Post: 12-04-2007, 11:52 AM
  2. Re: function prototype
    By Application Development in forum c++
    Replies: 0
    Last Post: 12-04-2007, 10:54 AM
  3. What should be the prototype of this function ? (noobie)
    By Application Development in forum C
    Replies: 6
    Last Post: 10-19-2007, 12:36 PM
  4. Self referencing function prototype typedef
    By Application Development in forum C
    Replies: 2
    Last Post: 07-19-2007, 08:19 AM
  5. Calling clarion DLL function from C++ prototype
    By Application Development in forum Clarion
    Replies: 3
    Last Post: 05-12-2006, 10:27 PM