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 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.


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