This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Why do not work?, is the same.
- From: "Fco. J" <rootag at terra dot es>
- To: gcc-help at gcc dot gnu dot org
- Date: Tue, 13 Sep 2005 13:23:25 +0200
- Subject: 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.