This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Why do not work?, is the same.


Block A: and B: are the same, but B: segfault.
> #include <stdio.h> 
> 
> #define SIZE_MARCA (256 + 62) 
> 
> typedef struct Marca
> {
>   unsigned char str[SIZE_MARCA];
>   unsigned int returned;
> } marc;
> 
> static struct Marca
> marca (const unsigned char *page, const unsigned int id)
> {
>   struct Marca marca;
> 
>   if (sprintf (marca.str, "%sTralara%u",page, (unsigned int) id) <= 0)
>     {
>       printf ("Error de salida de sprintf\n");
>       marca.returned = 0;
>     };
>   marca.returned = 1;
>   return marca;
> }
> 
> int
> main ()
> {
> struct Marca tmp;
> /*struct Marca (*puntero) (const unsigned char *page, const unsigned int id);*/
> /* A: */
> tmp.str = marca("server_form.html", 1).str;
> printf("TMP=%s\n",tmp.str);
> 
> /* B: */
>   printf ("1=%s \n", marca("server_form.html", 1).str);
>   exit (0);
> }

Output:

> ./tes2
> TMP=server_form.htmlTralara1
> Fallo de segmento

Where is the problem?

This days worked with functions an args hard. I can not understand very
well how gcc get functions returned values. Seems that evaluate all
functions before call mother function, but the problem is that functions
returned  values are not stored between calls, in the same mother
function va_args.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]