H
Hal Styli
/*hello could someone please help me with the
errors i get related to pointers to arrays of ints.
I want to declare something like
int *d[] = { 7, 11, 18, 54, 64, 55, 37, 38, };
rather than
int d[] = { 7, 11, 18, 54, 64, 55, 37, 38, };
It seems to work in the code below but I get compile
warnings and Im concerned about portability.
thanks in advance Hal. */
/*------<start of code>------------------*/
#include <stdio.h>
#define entries(x) ( sizeof(x) / sizeof(x[0]) )
#define max entries(a)
#define pr(x) printf( "%s=%3d ", #x, x );
#define prln(x) printf( "%s=%3d\n", #x, x );
int main()
{
int *p,i;
int x[] = { 23,45,46,77,18,69,37,12,63,74 };
int *b = (int *) &x;
/* Now try and declare without intermediate variable.
* My compiler gives (8) nonportable pointer conversion
* warnings...*/
int *d[] = { 7, 11, 18, 54, 64, 55, 37, 38, };
/*---------------------------------------------*/
putchar('\n'); pr(entries(x)); putchar('\n');
for( i=0,p=x; i<entries(x) ; i++ , p++ )
pr(*p);
putchar('\n');
/*---------------------------------------------*/
putchar('\n'); pr(entries(b)); putchar('\n');
for( i=0,p=b; i<entries(b) ; i++ , p++ )
pr(*p);
putchar('\n');
/*---------------------------------------------*/
putchar('\n'); pr(entries(d)); putchar('\n');
/* compiler complains about the p=d in this
* for() statement: Suspicious pointer conversion*/
for( i=0, p=d; i<entries(d) ; i++ , p++ )
pr(*p);
/*---------------------------------------------*/
return 0;
}
/*------<end of code>-<start of output>--------*/
entries(x)= 10
*p= 23 *p= 45 *p= 46 *p= 77 *p= 18 *p= 69 *p= 37 *p= 12 *p= 63 *p= 74
entries(b)= 1
*p= 23
entries(d)= 8
*p= 7 *p= 11 *p= 18 *p= 54 *p= 64 *p= 55 *p= 37 *p= 38
/*-----------------<end of output>----------------*/
errors i get related to pointers to arrays of ints.
I want to declare something like
int *d[] = { 7, 11, 18, 54, 64, 55, 37, 38, };
rather than
int d[] = { 7, 11, 18, 54, 64, 55, 37, 38, };
It seems to work in the code below but I get compile
warnings and Im concerned about portability.
thanks in advance Hal. */
/*------<start of code>------------------*/
#include <stdio.h>
#define entries(x) ( sizeof(x) / sizeof(x[0]) )
#define max entries(a)
#define pr(x) printf( "%s=%3d ", #x, x );
#define prln(x) printf( "%s=%3d\n", #x, x );
int main()
{
int *p,i;
int x[] = { 23,45,46,77,18,69,37,12,63,74 };
int *b = (int *) &x;
/* Now try and declare without intermediate variable.
* My compiler gives (8) nonportable pointer conversion
* warnings...*/
int *d[] = { 7, 11, 18, 54, 64, 55, 37, 38, };
/*---------------------------------------------*/
putchar('\n'); pr(entries(x)); putchar('\n');
for( i=0,p=x; i<entries(x) ; i++ , p++ )
pr(*p);
putchar('\n');
/*---------------------------------------------*/
putchar('\n'); pr(entries(b)); putchar('\n');
for( i=0,p=b; i<entries(b) ; i++ , p++ )
pr(*p);
putchar('\n');
/*---------------------------------------------*/
putchar('\n'); pr(entries(d)); putchar('\n');
/* compiler complains about the p=d in this
* for() statement: Suspicious pointer conversion*/
for( i=0, p=d; i<entries(d) ; i++ , p++ )
pr(*p);
/*---------------------------------------------*/
return 0;
}
/*------<end of code>-<start of output>--------*/
entries(x)= 10
*p= 23 *p= 45 *p= 46 *p= 77 *p= 18 *p= 69 *p= 37 *p= 12 *p= 63 *p= 74
entries(b)= 1
*p= 23
entries(d)= 8
*p= 7 *p= 11 *p= 18 *p= 54 *p= 64 *p= 55 *p= 37 *p= 38
/*-----------------<end of output>----------------*/