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. Advertisements

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. RA Scheltema
    Replies:
    3
    Views:
    620
    RA Scheltema
    Jan 6, 2004
  2. Gunnar G

    struct in struct

    Gunnar G, May 31, 2004, in forum: C++
    Replies:
    14
    Views:
    1,048
  3. DanielEKFA
    Replies:
    8
    Views:
    859
    DanielEKFA
    May 16, 2005
  4. M Kumar

    struct initializer { 0 }

    M Kumar, Sep 28, 2003, in forum: C Programming
    Replies:
    2
    Views:
    502
    Ivan Vecerina
    Sep 28, 2003
  5. James Harris
    Replies:
    4
    Views:
    1,796
    James Harris
    Oct 9, 2003
  6. Chris Fogelklou
    Replies:
    36
    Views:
    1,857
    Chris Fogelklou
    Apr 20, 2004
  7. Laurent Deniau

    struct initializer efficiency and portability

    Laurent Deniau, Aug 28, 2007, in forum: C Programming
    Replies:
    1
    Views:
    317
    Laurent Deniau
    Aug 28, 2007
  8. xmllmx
    Replies:
    4
    Views:
    397
    Zhihao Yuan
    Dec 17, 2012
Loading...