473,395 Members | 1,972 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.

dereferencing pointer to incomplete type

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.

I have a struct like:
struct node {
time_t utc;
};

And the code that generates the error during compilation:
int cmputc(const void *x, const void *y) {
struct tnode * const *a = x;
struct tnode * const *b = y;
int retv = 0;

if((*a)->utc < (*b)->utc)
retv = -1;
else if((*a)->utc == (*b)->utc)
retv = 0;
else
retv = 1;

return retv;
}

Does anyone know what I am doing wrong ?

Thank you for your explanation.

Steven.
Jan 7 '06 #1
5 4137

Ooopss..
Sorry. already solved..... :-) It's in the name using node in the
structure declaration and tnode in the compare function .. aiiii..

Thankx anyway.. [blush]

On Sat, 07 Jan 2006 12:42:39 +0100, Steven <St****@yahoo.com> wrote:
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.

I have a struct like:
struct node {
time_t utc;
};

And the code that generates the error during compilation:
int cmputc(const void *x, const void *y) {
struct tnode * const *a = x;
struct tnode * const *b = y;
int retv = 0;

if((*a)->utc < (*b)->utc)
retv = -1;
else if((*a)->utc == (*b)->utc)
retv = 0;
else
retv = 1;

return retv;
}

Does anyone know what I am doing wrong ?

Thank you for your explanation.

Steven.

Jan 7 '06 #2
Steven a écrit :
Be sure that this structure definition ...
struct node {
time_t utc;
};
.... is visible from ...
int cmputc(const void *x, const void *y) {
struct tnode * const *a = x;
struct tnode * const *b = y;


.... this function. Typically, it sould be placed in a header and
included where you need it.

--
A+

Emmanuel Delahaye
Jan 7 '06 #3
Steven <St****@yahoo.com> wrote:
I have a struct like:
struct node {
time_t utc;
};
Right...
int cmputc(const void *x, const void *y) {
struct tnode * const *a = x;
struct tnode * const *b = y;


So what's a struct tnode? Perhaps this is related to your problem?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jan 7 '06 #4
>int cmputc(const void *x, const void *y) {
struct tnode * const *a = x;
struct tnode * const *b = y;


You can't dereference a void pointer; you need to cast it.

int cmputc(const void *x, const void *y) {
struct tnode * const *a = (struct tnode * const *)x;
struct tnode * const *b = (struct tnode * const *)y;

Jan 9 '06 #5
dwks wrote:

Please leave in attributions so we can see who you are replying to.
int cmputc(const void *x, const void *y) {
struct tnode * const *a = x;
struct tnode * const *b = y;
You can't dereference a void pointer; you need to cast it.


The above is not dereferencing anything, it is assigning and is
perfectly valid in C. It is C++ which does not allow it, but that is a
different language.
int cmputc(const void *x, const void *y) {
struct tnode * const *a = (struct tnode * const *)x;
struct tnode * const *b = (struct tnode * const *)y;


Your suggestion above is far harder to read, so I would recommend
sticking with the perfectly legal option of not casting.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Jan 9 '06 #6

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

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 =...
7
by: Vivi | last post by:
Hello everybody, I'm writing a game program, and i have compilations errors.. :confused: typedef struct { struct lieu* cont; struct joueur* j;
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
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: 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
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
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,...

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.