473,951 Members | 16,311 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4160

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.c om> 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.c om> 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)cybers pace.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
16178
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 to pass both as "void *buf" so that it can accept any data type. But since I access the buffer and try to assign its elements to another I get compile errors (I have pasted at the end). Now my question is how can I pass the i/p and o/p buffers...
22
2254
by: Neo | last post by:
Hi Folks, #include<stdio.h> int main() { int (*p); int arr; int i;
204
13230
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};
7
51161
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
3876
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 *ipc_graph_pointer;
4
5248
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 = find_task_by_id(getpid()); 7. printf("%s",my->comm); error: dereferencing pointer to incomplete type
5
3201
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), "ctx->statemachine != NULL", TRUE); backend_sm_check_globals(check);
6
3690
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 = (struct nlmsghdr *) skb->data" line and also not able include "net/sock.h" header file. plz help me how can solve this Thanks
5
9494
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 initialization stuff */ struct adapter_struct *adapter = netdev_priv(netdev);
0
10174
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9997
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
11201
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...
1
11378
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10704
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7445
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6237
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
6359
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.