473,407 Members | 2,359 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,407 software developers and data experts.

dereferencing pointer to incomplete type

Hi list !!!
I came across "dereferencing pointer to incomplete type" eror while compiling my code....

I have defined one structure as follows

typedef struct {
int a;
int b;
void ( * add ) ( int x , int y );
}add_t;

And in main program

int main () {

add_t *obj;
obj->a=12;
obj->b=34;
obj->add ( obj->a , obj->b ) ;

}

while compling it I got yhis error..

Can any one solve this?????
Jul 23 '07 #1
3 1102
Three things I see.

1) You really want to be using a class here. Typedef struct is really old data types with C that just had data. If you're doing functions, use a class.

2) The method declaration is wrong. Do not surround the method name with parens.

3) You never defined what add does. So its incomplete.

With these mind try:

Expand|Select|Wrap|Line Numbers
  1. class add_t {
  2.  public:
  3.  
  4.  int a;
  5.  int b;
  6.  int ( int x , int y ) { return (x+y); }
  7. }
After you get that working you can add things like a constructor and move the data elements to the private class storage. If you want to do a typedef for some reason, you'll want to do:

typedef struct {
int a;
int b;
}add_t;

Expand|Select|Wrap|Line Numbers
  1. int
  2. add (add_t *obj_ptr)
  3. {
  4. return (obj_ptr->a + obj_ptr->b);
  5. }
Jul 23 '07 #2
Hi Benny

Thanks for u r reply..
I am trying this in C not in C++.
Cause my module dosn't permit me to use C++.
One more add function simply adds two int. nothing else.

If possible show me the way in C to achive this.

Thanks
Santosh
Jul 23 '07 #3
weaknessforcats
9,208 Expert Mod 8TB
This code:
int main () {

add_t *obj;
obj->a=12;
obj->b=34;
obj->add ( obj->a , obj->b ) ;

}
needs some work.

1) You declare an add_t pointer but you never put the address of an add_t object in the pointer. You can't use an uninitialized pointer.

2) add_t has a function pointer as a member but there is no function named add() whose address can be put in that pointer. Again, you need to initialize a pointer before using it.
Jul 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Pushkar Pradhan | last post by:
I have some functions which take as i/p a buffer (it can be float, char, or 16 bit, int etc.). The result is another o/p buffer, its type is also flexible (it could be a float, char etc.). I try...
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 =...
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...
5
by: Steven | last post by:
Hello, I get the following message during compilation: `dereferencing pointer to incomplete type' It stems from the compare function I use with qsort() and I am not quite sure how to fix it....
8
by: friend.05 | last post by:
I have three files. graph.h: My header file where I have typedef for my structure and function delcaration typedef struct _ipc_actors ipc_graph_actors; typedef ipc_graph_type...
4
by: Pritam | last post by:
line 7: error: dereferencing pointer to incomplete type 1. #include<stdio.h> 2. #include<sys/stat.h> 3. #include<stdlib.h> 4. void execname() { 5. struct task_struct *my; 6. my =...
5
by: tejesh | last post by:
I am trying to compile the following code int backend_sm_run(struct interface_data *ctx) { xsup_assert((ctx != NULL), "ctx != NULL", TRUE); xsup_assert((ctx->statemachine != NULL),...
6
by: hnshashi | last post by:
I have written kernel(2.4) module to communicate with user application using "Netlink Socket". I am getting compilation error "Dereferencing pointer to incomplete type" in kernel module for "nlh...
5
by: Anuz | last post by:
Hi all, While compiling a driver, I am getting this error: error: dereferencing pointer to incomplete type int __kc_adapter_clean(struct net_device *netdev, int *budget) { /*some...
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
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:
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
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...
0
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,...
0
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...

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.