struct initializer efficiency

Discussion in 'C Programming' started by Laurent Deniau, Aug 28, 2007.

  1. I was wondering if there is any good reason (semantic) to assume that
    the following three code do not have the same efficiency (both space
    and time):

    struct A { int a,b,c; }; // could other types than int and with less/
    more fields.
    void g(struct A*);

    // 1st case, C99
    void f(int a, int b, int c) {
    g(&(struct A*){ a,b,c }); // compound litteral
    }

    // 2nd case, C99
    void f(int a, int b, int c) {
    struct A a = { a,b,c }; // non-constant struct initializer
    g(&a);
    }

    // 3rd case, C89
    void f(int a, int b, int c) {
    struct A a;
    = { a,b,c }; // non-constant struct initializer
    g(&a);
    }
     
    Laurent Deniau, Aug 28, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. M Kumar

    struct initializer { 0 }

    M Kumar, Sep 28, 2003, in forum: C Programming
    Replies:
    2
    Views:
    415
    Ivan Vecerina
    Sep 28, 2003
  2. Chris Fogelklou
    Replies:
    36
    Views:
    1,447
    Chris Fogelklou
    Apr 20, 2004
  3. Laurent Deniau

    struct initializer efficiency and portability

    Laurent Deniau, Aug 28, 2007, in forum: C Programming
    Replies:
    1
    Views:
    275
    Laurent Deniau
    Aug 28, 2007
  4. Richard
    Replies:
    0
    Views:
    432
    Richard
    Oct 20, 2009
  5. Thomas J. Gritzan

    Re: initializer list of the struct

    Thomas J. Gritzan, Oct 20, 2009, in forum: C++
    Replies:
    0
    Views:
    435
    Thomas J. Gritzan
    Oct 20, 2009
Loading...

Share This Page