473,389 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,389 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 7141
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Xiangliang Meng | last post by:
Hi, all. As far as I know, the speical arithmetic operator on void pointer is an externsion in GNU CC. However, I could not find the relative topics in C99. Would someone like to help me find...
22
by: Neo | last post by:
Hi Folks, #include<stdio.h> int main() { int (*p); int arr; int i;
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
16
by: aegis | last post by:
Given the following: int a = 10; int *p; void *p1; unsigned char *p2; p = &a;
41
by: Alexei A. Frounze | last post by:
Seems like, to make sure that a pointer doesn't point to an object/function, NULL (or simply 0) is good enough for both kind of pointers, data pointers and function pointers as per 6.3.2.3: 3 An...
48
by: yezi | last post by:
Hi, all: I want to record some memory pointer returned from malloc, is possible the code like below? int memo_index; int i,j; char *tmp; for (i=0;i<10;i++){
26
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I...
9
by: WaterWalk | last post by:
Hello. When I practice pointers, I write code like the following: int *pn1; void **pv = (void **)&pn1; *pv = malloc(sizeof(int)); *pn1 = 1; It seems to work. But when I consult n1124(the draft...
50
by: Juha Nieminen | last post by:
I asked a long time ago in this group how to make a smart pointer which works with incomplete types. I got this answer (only relevant parts included): ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.