Why do not work?, is the same.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux