c/9540: C99 initializers generate lots of code

Marius Bernklev gcc-bugs@gcc.gnu.org
Mon Feb 3 12:34:00 GMT 2003


bangerth@dealii.org writes:

> Synopsis: C99 initializers generate lots of code
>
> State-Changed-From-To: open->feedback
> State-Changed-By: bangerth
> State-Changed-When: Sun Feb  2 22:15:57 2003
> State-Changed-Why:
>     Can you send a self-contained code example that shows this?
>     
>     Thanks
>      Wolfgang
>
> http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=9540
>

Certainly. :)


Here goes:


// Start of vector.c
#include <stdlib.h>  // well, I need size_t

// imaginary garbage collector allocator
extern void *gc_malloc(size_t);

struct string {
  size_t size;
  size_t length;
  char *restrict string;
  int hash;
};

struct string *new_vector1( const size_t length ) {
  struct string *const restrict result = gc_malloc( sizeof *result );

  *result = (struct string) { .size = sizeof *result,
                              .length = length,
                              .string = gc_malloc( length ),
                              .hash = -1 };

  return result;
}

struct string *new_vector2( const size_t length ) {
  struct string *const restrict result = gc_malloc( sizeof *result );

  result->size = sizeof *result;
  result->length = length;
  result->string = gc_malloc( length );
  result->hash = -1;
  
  return result;
}
---------------------------

with gcc 3.2.1 on x86, with the command line

gcc -std=c99 -S vector.c,

the code generated for new_vector1 is somewhat larger than for
new_vector2.



Marius
-- 
<URL: http://home.ifi.uio.no/~mariube/ >

Life sucks.  Death swallows.



More information about the Gcc-bugs mailing list