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. 6 7139
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
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
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>>
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
by: Neo |
last post by:
Hi Folks,
#include<stdio.h>
int main()
{
int (*p);
int arr;
int i;
|
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 =...
|
by: aegis |
last post by:
Given the following:
int a = 10;
int *p;
void *p1;
unsigned char *p2;
p = &a;
|
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...
|
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++){
|
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...
|
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...
|
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):
...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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...
| |