473,545 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer problem

kc
Hi,
i am getting a warning when compiling my program...
blbp_eom_isr_re venue.c", line 739: warning 527: Integral value
implicitly converted to pointer in assignment.
blbp_eom_isr_re venue.c", line 739: warning 563: Argument #4 is not the
correct type.

and at line 739:-

qsort((void *)Buff, totalRecs, sizeof(strcture _name), (int)
(*blbp_CtnRecCo mpare));

and the function blbp_CtnRecComp are is -
int blbp_CtnRecComp are (strcture_name Rec_1,
strcture_name Rec_2)
{
return (strcmp (Rec_1.field_na me, Rec_2.field_nam e));
}

Thanks for the solutions.

Sep 8 '06 #1
5 5328
In article <11************ **********@e3g2 000cwe.googlegr oups.com>,
kc <kc***********@ gmail.comwrote:
>i am getting a warning when compiling my program...
blbp_eom_isr_r evenue.c", line 739: warning 527: Integral value
implicitly converted to pointer in assignment.
blbp_eom_isr_r evenue.c", line 739: warning 563: Argument #4 is not the
correct type.
>and at line 739:-
>qsort((void *)Buff, totalRecs, sizeof(strcture _name), (int)
(*blbp_CtnRecC ompare));
>and the function blbp_CtnRecComp are is -
int blbp_CtnRecComp are (strcture_name Rec_1,
strcture_name Rec_2)
blbp_CtnRecComp are is a function, but in most cases when you aren't
actually calling the function, mentioning the name of the function
silently gets you the address of the function instead.

In your call to qsort, you then take that function address and
try to dereference it, which gets you back to the function again.
Your (int) in front of that then converts that from whatever type
it is (probably a function pointer) to an integral type, probably
losing address information along the way. qsort() expects a function
pointer at that point, so C is going to try to convert the int
into a function pointer, which is what is generating the first warning
about integral value converted to pointer. And because the integral
value is not the type of function pointer that qsort expects, you
get the second warning.

In order to fix the problem, you need to cast blbp_CtnRecComp are
to the correct type as you pass it in. Your reference book should
have several examples of the correct syntax.
--
Prototypes are supertypes of their clones. -- maplesoft
Sep 8 '06 #2
"kc" <kc***********@ gmail.comwrites :
qsort((void *)Buff, totalRecs, sizeof(strcture _name), (int)
(*blbp_CtnRecCo mpare));
This attempts to cast a pointer to function to type `int'.

Also, the cast to void * is suspicious.

"kc" <kc***********@ gmail.comwrites :
int blbp_CtnRecComp are (strcture_name Rec_1,
strcture_name Rec_2)
{
return (strcmp (Rec_1.field_na me, Rec_2.field_nam e));
}
This is not the correct type. It should be declared as
int blbp_CtnRecComp are (const void *, const void *);

If you declare it correctly, you don't need any cast at all in
the call to qsort.
--
int main(void){char p[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Sep 8 '06 #3
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:

[call to qsort]
In order to fix the problem, you need to cast blbp_CtnRecComp are
to the correct type as you pass it in.
No. The OP needs to declare blbp_CtnRecComp are to be of the
correct type. Then the cast is unnecessary.

If the cast is necessary, then the call to qsort is wrong.
--
"Some people *are* arrogant, and others read the FAQ."
--Chris Dollin
Sep 8 '06 #4
Walter Roberson said:
In article <87************ @benpfaff.org>,
Ben Pfaff <bl*@cs.stanfor d.eduwrote:
<snip>
>
>>If the cast is necessary, then the call to qsort is wrong.

K&R2 section 5.11 "Pointers to Functions", page 119
....gives a lousy illustration of how to use qsort. Ben is right.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Sep 8 '06 #5
ro******@ibd.nr c-cnrc.gc.ca (Walter Roberson) writes:
In article <87************ @benpfaff.org>,
Ben Pfaff <bl*@cs.stanfor d.eduwrote:
>>ro******@ibd. nrc-cnrc.gc.ca (Walter Roberson) writes:
>>[call to qsort]
>>In order to fix the problem, you need to cast blbp_CtnRecComp are
to the correct type as you pass it in.
>>No. The OP needs to declare blbp_CtnRecComp are to be of the
correct type. Then the cast is unnecessary.
>>If the cast is necessary, then the call to qsort is wrong.

K&R2 section 5.11 "Pointers to Functions", page 119

[...]
void qsort(void *lineptr[], int left, int right,
int (*comp)(void *, void *));
int numcmp(char *, char *);
[...]
qsort((void **) lineptr, 0, nlines-1,
(int (*)(void*,void* ))(numeric ? numcmp : strcmp));
[...]

Did something relevant change between the publication of K&R2 and
the C89 standard such that K&R2 became incorrect ?
This part of K&R2 is badly written, as admitted on the official
errata page at:
http://cm.bell-labs.com/cm/cs/cbook/2ediffs.html

The relevant text is:

119-121(5.11): The qsort discussion needs recasting in
several ways. First, qsort is a standard routine in ANSI/ISO
C, so the rendition here should be given a different name,
especially because the arguments to standard qsort are a bit
different: the standard accepts a base pointer and a count,
while this example uses a base pointer and two offsets.

Also, the comparison-routine argument is not treated
well. The call shown on p 119, with an argument

(int (*)(void*,void* ))(numeric? numcmp : strcmp)

is not only complicated, but only barely passes muster. Both
numcmp and strcmp take char * arguments, but this expression
casts pointers to these functions to a function pointer that
takes void * arguments. The standard does say that void * and
char * have the same representation, so the example will
almost certainly work in practice, and is at least defensible
under the standard. There are too many lessons in these
pages.
--
char a[]="\n .CJacehknorstu" ;int putchar(int);in t main(void){unsi gned long b[]
={0x67dffdff,0x 9aa9aa6a,0xa77f fda9,0x7da6aa6a ,0xa67f6aaa,0xa a9aa9f6,0x11f6} ,*p
=b,i=24;for(;p+ =!*p;*p/=4)switch(0[p]&3)case 0:{return 0;for(p--;i--;i--)case+
2:{i++;if(i)bre ak;else default:continu e;if(0)case 1:putchar(a[i&15]);break;}}}
Sep 8 '06 #6

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

Similar topics

4
2124
by: Carsten Spieß | last post by:
Hello all, i have a problem with a template constructor I reduced my code to the following (compiled with gcc 2.7.2) to show my problem: // a base class class Base{}; // two derived classes
5
6040
by: John N. | last post by:
Hi All, Here I have a linked list each containing a char and is double linked. Then I have a pointer to an item in that list which is the current insertion point. In this funtion, the user hits the right and left keys to move this insertion point (cursor) Here is the problem:
7
5168
by: Mike D. | last post by:
I have a problem with a dynamic library I am developing, but it is really more of a pointer issue than anything else. Hopefully someone here can lend me some assistance or insight into resolving this. Ok... here goes.... I have a function that passes a pointer to a string to another function. For example: int FunctionA ()
10
4092
by: Kieran Simkin | last post by:
Hi, I wonder if anyone can help me, I've been headscratching for a few hours over this. Basically, I've defined a struct called cache_object: struct cache_object { char hostname; char ipaddr; };
204
12927
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
2038
by: Marcelo | last post by:
Hi everybody, I don't understand why I am having a problem in this code. The problem is that my pointer *phist in main method, it is declared. Then I send the pointer to my method, and this method creates a new object (a Matrix) for it. I suppose that after the new operator, my pointer is pointing to an object, so when the method has...
51
10240
by: Joe Van Dyk | last post by:
When you delete a pointer, you should set it to NULL, right? Joe
2
2824
by: toton | last post by:
Hi, This is continuation of topic pointer & reference doubt. http://groups.google.com/group/comp.lang.c++/browse_thread/thread/df84ce6b9af561f9/76304d7d77f6ccca?lnk=raot#76304d7d77f6ccca But I think it is better to have a new topic rather than continuing on old one. As now I am sure pointer to reference and reference to pointer are freely...
9
3004
by: junky_fellow | last post by:
Hi, To print the pointer using printf(), we convert it to (void *) . printf("%p",(void *)ptr); My question is how printf() determine which type of pointer is passed to it and prints its value accordingly ? I have this doubt as different pointers may have different representation and different size. So, how does printf determine
6
2501
by: worlman385 | last post by:
For pointer and non-pointer initialization of an object like MyCar mycar; MyCar* mycar = new MyCar(); I heard from other people saying if object i create must live outside scape, then I use pointer version, else if only use object for a limited scope, then use non-pointer version. Does limited scope means the object is only used in...
0
7668
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. ...
0
7923
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...
1
7437
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...
0
5984
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...
1
5343
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...
0
4960
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...
0
3466
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...
1
1025
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
722
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...

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.