471,049 Members | 1,573 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,049 software developers and data experts.

Pointer problems

Hi all,
I'm using the following code, but there's a problem somewhere.

// Typedef af 8 arrays af 7 pointere til ints
#include <iostream>
using namespace std;

int main()
{
typedef int ((*test)[7])[8];

int a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7;

// array af 7 pointere til ints

int* data[] = {&a, &b, &c, &d, &e, &f, &g};

test p;

p[0] = &data;
p[1] = &data;
p[2] = &data;
p[3] = &data;
p[4] = &data;
p[5] = &data;
p[6] = &data;
p[7] = &data;

return 0;

}

I'm gettin the following error messages:

g++ 593-2.cpp
593-2.cpp: I function 'int main()':
593-2.cpp:23: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:24: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:25: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:26: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:27: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:28: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:29: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:30: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'

Can any of you tell me whats wrong?

--

// Morten - www.mortenvp.dk
Jul 23 '05 #1
2 2258
Morten V Pedersen wrote:
I'm using the following code, but there's a problem somewhere.

// Typedef af 8 arrays af 7 pointere til ints
A pointer to int:

typedef int *pint;

An array of 7 pointers to int

typedef int *sevenpint[7];

An array of 8 array of 7 pointers to int

typedef int *eightarraysofsevenpint[8][7];

#include <iostream>
using namespace std;

int main()
{
typedef int ((*test)[7])[8];
Wrong dimensions.

typedef int *test[8][7];

int a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7;

// array af 7 pointere til ints
int* data[] = {&a, &b, &c, &d, &e, &f, &g};

test p;

p[0] = &data;
p[1] = &data;
p[2] = &data;
p[3] = &data;
p[4] = &data;
p[5] = &data;
p[6] = &data;
p[7] = &data;
If 'p' is an array of arrays, then every element if it is an array.
p[0] is an array, p[1] is an array, etc. Arrays cannot be assigned to.

Nor can they be initialised from a single variable ('data' decays to
a pointer to a pointer to int if used in an expression). You need

test p = { { &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g } };

return 0;

}

I'm gettin the following error messages:

g++ 593-2.cpp
593-2.cpp: I function 'int main()':
593-2.cpp:23: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:24: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:25: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:26: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:27: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:28: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:29: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'
593-2.cpp:30: error: incompatible types in assignment of `int* (*)[7]' to `
int[7][8]'

Can any of you tell me whats wrong?


Plenty.

V
Jul 23 '05 #2
Victor Bazarov wrote:
Morten V Pedersen wrote:
I'm using the following code, but there's a problem somewhere.

// Typedef af 8 arrays af 7 pointere til ints

A pointer to int:

typedef int *pint;

An array of 7 pointers to int

typedef int *sevenpint[7];

An array of 8 array of 7 pointers to int

typedef int *eightarraysofsevenpint[8][7];

#include <iostream>
using namespace std;

int main()
{
typedef int ((*test)[7])[8];

Wrong dimensions.

typedef int *test[8][7];

int a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7;

// array af 7 pointere til ints
int* data[] = {&a, &b, &c, &d, &e, &f, &g};

test p;

p[0] = &data;
p[1] = &data;
p[2] = &data;
p[3] = &data;
p[4] = &data;
p[5] = &data;
p[6] = &data;
p[7] = &data;

If 'p' is an array of arrays, then every element if it is an array.
p[0] is an array, p[1] is an array, etc. Arrays cannot be assigned to.

Nor can they be initialised from a single variable ('data' decays to
a pointer to a pointer to int if used in an expression). You need

test p = { { &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g },
{ &a, &b, &c, &d, &e, &f, &g } };

return 0;

}

I'm gettin the following error messages:

g++ 593-2.cpp
593-2.cpp: I function 'int main()':
593-2.cpp:23: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:24: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:25: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:26: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:27: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:28: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:29: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'
593-2.cpp:30: error: incompatible types in assignment of `int* (*)[7]'
to `
int[7][8]'

Can any of you tell me whats wrong?


Plenty.

V


Thx for the help, i got it working now..

--

// Morten - www.mortenvp.dk
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Thomas Baier | last post: by
21 posts views Thread by MOvetsky | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
2 posts views Thread by Mike | last post: by
13 posts views Thread by william | last post: by
19 posts views Thread by mail1779205 | last post: by
2 posts views Thread by hs.samix | last post: by
26 posts views Thread by Ioannis Vranos | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.