473,395 Members | 1,343 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,395 software developers and data experts.

derefrencing pointer to incomplete type

1)

#include <stdio.h>
#include <stdlib.h>
#include "graph.h"

#define MAX_VTX 4
struct _graph_vertex {
char *label;
int exectime;

};
struct _graph_edge {

int produced, consumed, delay;

};
struct _graph {

graph_vertex vertices[MAX_VTX];
graph_edge_pointer adjmtx[MAX_VTX][MAX_VTX];

};
graph_pointer graph_construct(int *src, int *snk, int cnt)
{
graph_type g;
graph_pointer gpt;
graph_vertex_pointer gvt;
int i,j;

for(i=0 ; i < MAX_VTX ; i++)
{
for(j=0 ; j < MAX_VTX; j++)
g.adjmtx[i][j]=NULL;
}
//for(i=0;i<MAX_VTX;i++)
//{
// for(j=0;j<MAX_VTX;j++)
//g.adjmtx[i][j]=(struct _graph_edge*)malloc(sizeof(struct
_graph_edge));
//
g.adjmtx[i][j]=(graph_edge_pointer)malloc(sizeof(graph_edge));
//}
for(i=0;i<MAX_VTX;i++)
{
gvt = &g.vertices[i];

gvt=(graph_vertex_pointer)malloc(sizeof(graph_vert ex));
}
for(i=0;i<cnt;i++)
{
g.adjmtx[src[i]][snk[j]]=(graph_edge_pointer)malloc(sizeof(graph_edge));

}
for(i=0;i<MAX_VTX;i++)
{
printf("Enter execution time for Vertex %d\n",i);
scanf("%d",&g.vertices[i].exectime);
printf("Enter label for Vertex %d\n",i);
scanf("%s",&g.vertices[i].label);
}
for(i=0;i<cnt;i++)
{
printf("Enter Produced for Edge %d\n",i);
scanf("%d", &g.adjmtx[src[i]][snk[j]]->produced);
printf("Enter Consumed for Edge %d\n",i);
scanf("%d", &g.adjmtx[src[i]][snk[j]]->produced);
printf("Enter Delay for Edge %d\n",i);
scanf("%d", &g.adjmtx[src[i]][snk[j]]->produced);
}
gpt = &g;
printf("%d",gpt->vertices[1].exectime);
return gpt;

}
2)

#include <stdio.h>
#include <stdlib.h>
#include "graph.h"

int main()
{
int src_vtx[]= {0,1,3,0,3};
int snk_vtx[] = {1,2,2,3,1};
int edgcnt = sizeof(src_vtx)/sizeof(int);
graph_pointer gp;
gp = graph_construct(src_vtx,snk_vtx,edgcnt);
printf("%d",gp->vertices[1].exectime);
I am getting error over here:
gcc : derefrencing pointer to incomplete type
vc++ : left of 'vertices' specifies undefined struct/union '_graph'
return 0;


3) graph.h
#ifndef _graph_h
#define _graph_h
#include "floatmath.h"
/* A vertex in a graph. */
typedef struct _graph_vertex graph_vertex;
/* A pointer to a graph vertex. */
typedef graph_vertex *graph_vertex_pointer;
/* An edge in a graph. */
typedef struct _graph_edge graph_edge;
/* A pointer to a graph edge. */
typedef graph_edge *graph_edge_pointer;
/* A graph. */
typedef struct _graph graph_type;
/* A pointer to a graph. */
typedef graph_type *graph_pointer;
/* An array of pointers to graph edges. */
typedef graph_edge_pointer *graph_edge_array;
graph_pointer graph_construct(int *, int *, int);
#endif

Sep 30 '06 #1
5 2059
Note:
- This has also been posted to gnu.gcc.help, message
<11*********************@e3g2000cwe.googlegroups.c om>
Please indicate this fact in all groups you post to, so you do not
make people tell you the same things independently.
- Your code contains much vertical spacing; I threw it out without
explicit notes.

friend.05 wrote:
1)

#include <stdio.h>
#include <stdlib.h>
#include "graph.h"

#define MAX_VTX 4

struct _graph_vertex {
Leading underscores do not "belong" to the user in many cases.
It is a good idea not to use them if you are not sure in which
cases they belong to you and in which they do not.

<snip>
//g.adjmtx[i][j]=(struct _graph_edge*)malloc(sizeof(struct
_graph_edge));
As illustrated by the above: // comments are bad for posting
code in usenet.
g.adjmtx[i][j]=(graph_edge_pointer)malloc(sizeof(graph_edge));
- This statement is outside of a loop.
- It is unnecessary to cast the return value of malloc(); this
can hide an error. If your compiler complains if you take away
the cast _and_ have included <stdlib.hthen you are compiling
C code with a C++ compiler (or in the compiler's C++ mode) --
bad idea.
- the favoured form of allocation around here is
T *p;
...
p = malloc(sizeof *p);
If the type of p changes, then nothing goes wrong.
- you forgot to check for malloc() success or failure.
<snip>
2)

#include <stdio.h>
#include <stdlib.h>
#include "graph.h"

int main()
{
int src_vtx[]= {0,1,3,0,3};
int snk_vtx[] = {1,2,2,3,1};
int edgcnt = sizeof(src_vtx)/sizeof(int);
graph_pointer gp;
gp = graph_construct(src_vtx,snk_vtx,edgcnt);
printf("%d",gp->vertices[1].exectime);
I am getting error over here:
gcc : derefrencing pointer to incomplete type
You did not give the structure definition in "graph.h" but
only said "I mean 'struct _graph *' whenever I say 'graph_pointer'".
The compiler only knows that there is a type "struct _graph" but
not what it looks like.
Either do not try to access the interna of your graphs from outside
the graph "library" or move the struct definitions to "graph.h".
vc++ : left of 'vertices' specifies undefined struct/union '_graph'

return 0;
You do not post your full programme -- this code will not compile.
3) graph.h
#ifndef _graph_h
#define _graph_h
#include "floatmath.h"
As you did not provide floatmath.h (or at least neglected to point
out which of "1)" and "2)" is supposed to be that), I cannot
compile your code -- you make it unnecessarily hard to help you.
/* A vertex in a graph. */
typedef struct _graph_vertex graph_vertex;

/* A pointer to a graph vertex. */
typedef graph_vertex *graph_vertex_pointer;

/* An edge in a graph. */
typedef struct _graph_edge graph_edge;

/* A pointer to a graph edge. */
typedef graph_edge *graph_edge_pointer;

/* A graph. */
typedef struct _graph graph_type;

/* A pointer to a graph. */
typedef graph_type *graph_pointer;

/* An array of pointers to graph edges. */
typedef graph_edge_pointer *graph_edge_array;

graph_pointer graph_construct(int *, int *, int);

#endif
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 30 '06 #2
thanks for ur help:

sorry for trouble

I am giving my floatmath.h:

#ifndef _floatmath_h
#define _floatmath_h

/* A vector of floating point (double-typed) numbers. */
typedef struct _floatmath_vector floatmath_vector;

/* Return a new vector with a given length, and a given sequence
(array) of
element values.
*/
floatmath_vector *floatmath_vectorNew(int, double *);

/* Given an index and a vector, return the element of the vector at
that index.
Vectors are indexed starting at zero.
*/
double floatmath_vectorElement(floatmath_vector *, int);

/* Given a vector, return the length (number of elements in) the
vector.
*/
int floatmath_vectorLength(floatmath_vector *);

/* Return the remainder when dividing the first number by the second.
*/
double floatmodulus(double, double);

/* Using Euclid's algorithm, return the greatest common divisor of two
numbers.
*/
double euclid(double, double);

/* Return the least common multiple of two numbers. */
double lcm(double, double);

/* Given pointers to the numerator and denominator of a fraction,
modify
the numerator and denominator so that the fraction is in reduced form.
*/
void reduce_fraction(double *, double *);

/* Given an array of floating point numbers and the length of the
array,
return the greatest common divisor of all elements in the array.
*/
double vect_gcd(double *, int);

#endif

Michael Mair wrote:
Note:
- This has also been posted to gnu.gcc.help, message
<11*********************@e3g2000cwe.googlegroups.c om>
Please indicate this fact in all groups you post to, so you do not
make people tell you the same things independently.
- Your code contains much vertical spacing; I threw it out without
explicit notes.

friend.05 wrote:
1)

#include <stdio.h>
#include <stdlib.h>
#include "graph.h"

#define MAX_VTX 4

struct _graph_vertex {

Leading underscores do not "belong" to the user in many cases.
It is a good idea not to use them if you are not sure in which
cases they belong to you and in which they do not.

<snip>
//g.adjmtx[i][j]=(struct _graph_edge*)malloc(sizeof(struct
_graph_edge));

As illustrated by the above: // comments are bad for posting
code in usenet.
g.adjmtx[i][j]=(graph_edge_pointer)malloc(sizeof(graph_edge));

- This statement is outside of a loop.
- It is unnecessary to cast the return value of malloc(); this
can hide an error. If your compiler complains if you take away
the cast _and_ have included <stdlib.hthen you are compiling
C code with a C++ compiler (or in the compiler's C++ mode) --
bad idea.
- the favoured form of allocation around here is
T *p;
...
p = malloc(sizeof *p);
If the type of p changes, then nothing goes wrong.
- you forgot to check for malloc() success or failure.
<snip>
2)

#include <stdio.h>
#include <stdlib.h>
#include "graph.h"

int main()
{
int src_vtx[]= {0,1,3,0,3};
int snk_vtx[] = {1,2,2,3,1};
int edgcnt = sizeof(src_vtx)/sizeof(int);
graph_pointer gp;
gp = graph_construct(src_vtx,snk_vtx,edgcnt);
printf("%d",gp->vertices[1].exectime);
I am getting error over here:
gcc : derefrencing pointer to incomplete type

You did not give the structure definition in "graph.h" but
only said "I mean 'struct _graph *' whenever I say 'graph_pointer'".
The compiler only knows that there is a type "struct _graph" but
not what it looks like.
Either do not try to access the interna of your graphs from outside
the graph "library" or move the struct definitions to "graph.h".
vc++ : left of 'vertices' specifies undefined struct/union '_graph'

return 0;

You do not post your full programme -- this code will not compile.
3) graph.h
#ifndef _graph_h
#define _graph_h
#include "floatmath.h"

As you did not provide floatmath.h (or at least neglected to point
out which of "1)" and "2)" is supposed to be that), I cannot
compile your code -- you make it unnecessarily hard to help you.
/* A vertex in a graph. */
typedef struct _graph_vertex graph_vertex;

/* A pointer to a graph vertex. */
typedef graph_vertex *graph_vertex_pointer;

/* An edge in a graph. */
typedef struct _graph_edge graph_edge;

/* A pointer to a graph edge. */
typedef graph_edge *graph_edge_pointer;

/* A graph. */
typedef struct _graph graph_type;

/* A pointer to a graph. */
typedef graph_type *graph_pointer;

/* An array of pointers to graph edges. */
typedef graph_edge_pointer *graph_edge_array;

graph_pointer graph_construct(int *, int *, int);

#endif

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Sep 30 '06 #3
friend.05 wrote:
#ifndef _floatmath_h
#define _floatmath_h
Michael Mair wrote:
Leading underscores do not "belong" to the user in many cases.
It is a good idea not to use them if you are not sure in which
cases they belong to you and in which they do not.
I like this convention:

#ifndef H_FLOATMATH_H
#define H_FLOATMATH_H

--
pete
Oct 1 '06 #4

friend.05 wrote:
1)

graph_pointer graph_construct(int *src, int *snk, int cnt)
{
graph_type g;
'g' is defined here.
graph_pointer gpt;
graph_vertex_pointer gvt;
int i,j;
....
>
gpt = &g;
Pointer 'gpt' points to 'g'. And 'g' is defined on stack, NOT heap.
printf("%d",gpt->vertices[1].exectime);
This is right because the function hasn't terminated.
return gpt;

}
....
>
printf("%d",gp->vertices[1].exectime);
So this is wrong. ;-(
return 0;
Oct 1 '06 #5
pete wrote:
friend.05 wrote:
>Michael Mair wrote:
>>Leading underscores do not "belong" to the user in many cases.
It is a good idea not to use them if you are not sure in which
cases they belong to you and in which they do not.

#ifndef _floatmath_h
#define _floatmath_h

I like this convention:

#ifndef H_FLOATMATH_H
#define H_FLOATMATH_H
I do too. The rationale behind it is that the leading H_ avoids
conflict with files whose names begin with e or E, while preservng
the convention of upper case for defines. The reason for avoiding
the E is that such names are reserved for the implementation, and
are actually used to define possible runtime system errors. I
adopted it after that was pointed out to me by someone on this
newsgroup.

--
Some useful references about C:
<http://www.ungerhu.com/jxh/clc.welcome.txt>
<http://www.eskimo.com/~scs/C-faq/top.html>
<http://benpfaff.org/writings/clc/off-topic.html>
<http://anubis.dkuug.dk/jtc1/sc22/wg14/www/docs/n869/(C99)
<http://www.dinkumware.com/refxc.html (C-library}
<http://gcc.gnu.org/onlinedocs/ (GNU docs)
<http://clc-wiki.net (C-info)
Oct 1 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Asfand Yar Qazi | last post by:
Hello. Partly for learning purposes, I have written a smart pointer class. Could you please tell me what's wrong with it? (I know there's something wrong with it, but just not what!) Note...
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++){
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.