This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Why not work is logical?
- From: Fran <list_c at yobinario dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Sat, 15 Apr 2006 13:14:24 +0000
- Subject: Why not work is logical?
Hello,
This do not work.
{
#define URI_MAX 512
#define a 3
unsigned int link_x=2;
char (*link)[][][URI_MAX];
...
link = (char (*)[link_x][a][URI_MAX]) malloc (sizeof (char) * link_x * (a) * (URI_MAX));
{
char (*pointer_links)[link_x][a][URI_MAX] = (char (*)[link_x][a][URI_MAX]) link;
snprintf (*(pointer_links)[0][0], URI_MAX, "http://www.gcc.com");
snprintf (*(pointer_links)[0][1], URI_MAX, "http://wwww.PPSON.com");
snprintf (*(pointer_links)[0][2], URI_MAX, "http://www.hpc.com");
...
for (contador_x = 0; contador_x < link_x ; contador_x++)
{
for (contador_y=0; contador_y < a; contador_y++)
{
printf ("LINK[%u][%u] = %s\n",contador_x,contador_y,*(pointer_links)[contador_x][contador_y]);
}
}
}
}
Output, see PPSN not PPSON.
LINK[0][0] = http://www.gcc.com
LINK[0][1] = http://www.PPSN.com
LINK[0][2] = http://www.hpc.com
...
In general this method do not work in arrays with n > 1.
Why do not work? GCC do not warn while compile about errors.
Thanks in advance.