473,698 Members | 2,571 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(m flops1, blkSz, NUMBASECASES);

void write_bc_perf(d ouble 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 7215
On Mon, 06 Oct 2003 00:57:07 -0500, Pushkar Pradhan
<pu*****@gri.ms state.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(d ouble 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(d ouble *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.ms state.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(m flops1, blkSz, NUMBASECASES);

void write_bc_perf(d ouble 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.m sstate.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(d ouble 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(d ouble *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.ms state.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(d ouble 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_basecase s.c: In function `write_bc_perf' :
exec_basecase s.c:120: arithmetic on pointer to an incomplete type
exec_basecase s.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.ms state.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(d ouble 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(d ouble *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(d ouble 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
1726
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 them out? in linux\mm\Slab.c, typedef struct slab_s { struct list_head list; unsigned long colouroff;
22
2220
by: Neo | last post by:
Hi Folks, #include<stdio.h> int main() { int (*p); int arr; int i;
204
13016
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 = {0,1,2,4,9};
16
2507
by: aegis | last post by:
Given the following: int a = 10; int *p; void *p1; unsigned char *p2; p = &a;
41
10033
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 integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.55) If a null pointer constant is converted to a pointer type, the resulting pointer, called a null pointer, is guaranteed...
48
2160
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
3052
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 read some of the items from the bottom up of the buffer, and some from the top down, moving the bottom items back to the new re-allocated bottom on every file read. Then when I've read all four files, I sort the top and bottom items separately...
9
1582
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 c99 standard with tc2), in section 6.3.2.3/7, it says: "A pointer to an object or incomplete type may be converted to a pointer to a different
50
4481
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): //------------------------------------------------------------------ template<typename Data_t> class SmartPointer { Data_t* data; void(*deleterFunc)(Data_t*);
0
8610
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9170
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9031
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7740
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6528
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.