471,066 Members | 1,298 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

arithmetic on pointer to an incomplete type

I tried to read the archives and solve this problem, but now I think I
better post my problem:
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)
{
......../*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1], mflops1[i]);
......../*other code*/
}

This is my compiler error:
psp1@leto:~/pdc$ gcc -g -o main exec_basecases.c gen_matrix.c codelets.c
exec_basecases.c: In function `write_bc_perf':
exec_basecases.c:120: arithmetic on pointer to an incomplete type
exec_basecases.c:120: arithmetic on pointer to an incomplete type

When I comment out the above fprintf.. and compile,
In gdb I try to access blockSz[i][0] in write_bc_perf function, I get
the correct values for i=0, but the values are incorrect for i=1, i=2, etc.
Can anyone point out the problem.

Nov 13 '05 #1
6 6418
On Mon, 06 Oct 2003 00:57:07 -0500, Pushkar Pradhan
<pu*****@gri.msstate.edu> wrote:
I tried to read the archives and solve this problem, but now I think I
better post my problem:
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)
{
......./*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1], mflops1[i]);
......./*other code*/
}


Does it work if you define the function like this:

void write_bc_perf(double *mflops1, int **blockSz, int numEntries)
{
......../*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1],
mflops1[i]);
......../*other code*/
}

?
Olli
Nov 13 '05 #2
Pushkar Pradhan <pu*****@gri.msstate.edu> writes:
I tried to read the archives and solve this problem, but now I
think I better post my problem:
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)
{
......./*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1], mflops1[i]);
......./*other code*/
}

This is my compiler error:
psp1@leto:~/pdc$ gcc -g -o main exec_basecases.c gen_matrix.c codelets.c
exec_basecases.c: In function `write_bc_perf':
exec_basecases.c:120: arithmetic on pointer to an incomplete type
exec_basecases.c:120: arithmetic on pointer to an incomplete type

When I comment out the above fprintf.. and compile,
In gdb I try to access blockSz[i][0] in write_bc_perf function, I
get the correct values for i=0, but the values are incorrect for
i=1, i=2, etc.
Can anyone point out the problem.


If you invoked gcc in strict ISO conformance mode by adding the
-ansi and -pedantic switches, you'd also get:

.... warning: array type has incomplete element type

Your declaration of the blockSz parameter is not legal in C. Make
it a complete type such as "int blockSz[][2]", and your problems
should be solved.

-Micah
Nov 13 '05 #3
On Mon, 06 Oct 2003 08:28:55 +0200, Oliver Fleischmann <sp**@go.cc>
wrote:
On Mon, 06 Oct 2003 00:57:07 -0500, Pushkar Pradhan
<pu*****@gri.msstate.edu> wrote:
I tried to read the archives and solve this problem, but now I think I
better post my problem:
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)
{
......./*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1], mflops1[i]);
......./*other code*/
}


Does it work if you define the function like this:

void write_bc_perf(double *mflops1, int **blockSz, int numEntries)


This should produce a diagnostic if the prototype is in scope at the
time the function is called. An int** is nothing like an int[N][M].

If the prototype is not in scope, I hope it invokes undefined behavior
because you have passed the function a completely different type than
it expects to receive. At the very least I would expect numerous run
time errors.
<<Remove the del for email>>
Nov 13 '05 #4
I tried both passing int **blockSz and declaring int blockSz[][2] = {
/*initializing*/}

int **blockSz gives this error:
psp1@leto:~/pdc$ gcc -g -o main exec_basecases.c gen_matrix.c codelets.c
exec_basecases.c: In function `main':
exec_basecases.c:73: warning: passing arg 2 of `write_bc_perf' from
incompatible pointer type

And int blockSz[][2], gives the same compile error as my previous
declaration.
Both give compile errors.

Micah Cowan wrote:
Pushkar Pradhan <pu*****@gri.msstate.edu> writes:

I tried to read the archives and solve this problem, but now I
think I better post my problem:
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)
{
......./*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1], mflops1[i]);
......./*other code*/
}

This is my compiler error:
psp1@leto:~/pdc$ gcc -g -o main exec_basecases.c gen_matrix.c codelets.c
exec_basecases.c: In function `write_bc_perf':
exec_basecases.c:120: arithmetic on pointer to an incomplete type
exec_basecases.c:120: arithmetic on pointer to an incomplete type

When I comment out the above fprintf.. and compile,
In gdb I try to access blockSz[i][0] in write_bc_perf function, I
get the correct values for i=0, but the values are incorrect for
i=1, i=2, etc.
Can anyone point out the problem.

If you invoked gcc in strict ISO conformance mode by adding the
-ansi and -pedantic switches, you'd also get:

... warning: array type has incomplete element type

Your declaration of the blockSz parameter is not legal in C. Make
it a complete type such as "int blockSz[][2]", and your problems
should be solved.

-Micah


Nov 13 '05 #5
Oliver Fleischmann <sp**@go.cc> writes:
On Mon, 06 Oct 2003 00:57:07 -0500, Pushkar Pradhan
<pu*****@gri.msstate.edu> wrote:
I tried to read the archives and solve this problem, but now I think I
better post my problem:
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)
{
......./*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1], mflops1[i]);
......./*other code*/
}


Does it work if you define the function like this:

void write_bc_perf(double *mflops1, int **blockSz, int numEntries)
{
......./*other code*/
fprintf(fp, "%dx%d %g\n", blockSz[i][0], blockSz[i][1],
mflops1[i]);
......./*other code*/
}

?


Hell no. Shouldn't even compile: definitely diagnostic ('course,
so does the above on a conformant implementation). You can't just
substitute a pointer-to-pointer for an array-of-arrays (or
pointer-to-array). Brush the dust off your C book and study the
differences between arrays and pointers. No, they're not always
just interchangeable.

-Micah
Nov 13 '05 #6

On Mon, 6 Oct 2003, Pushkar Pradhan wrote:

I tried both passing int **blockSz and declaring int blockSz[][2] = {
/*initializing*/}

int **blockSz gives this error:
Of course.
And int blockSz[][2], gives the same compile error as my previous
declaration.


Not really.
int main() {
int blkSz[NUMBASECASES][2] = { {2,2},
{2,3},
.....,
{6,6} };

write_bc_perf(mflops1, blkSz, NUMBASECASES);

void write_bc_perf(double mflops1[], int blockSz[][], int numEntries)

^^^^^^^^^^^^^^^
Change this to 'int blockSz[][2]' and re-compile.

-Arthur

Nov 13 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

22 posts views Thread by Neo | last post: by
204 posts views Thread by Alexei A. Frounze | last post: by
16 posts views Thread by aegis | last post: by
41 posts views Thread by Alexei A. Frounze | last post: by
48 posts views Thread by yezi | last post: by
9 posts views Thread by WaterWalk | 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.