By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,655 Members | 964 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,655 IT Pros & Developers. It's quick & easy.

what is the meaning of "lacks a cast" when compile

P: 12
when I compile my code, it show :
WARNING : passing `int' to argument 1 of `deleteQueue(itemType *, queue *)' lacks a cast
What is the meaning for this warning?
Where I should coorect in my code?

Expand|Select|Wrap|Line Numbers
  1. void Print(queue *q)
  2. {
  3. int j;
  4. if ((q->tail-q->head) >=5) 
  5. {        
  6.  for(j = 0;j < 5 ;j++)
  7. {
  8. printf("\nDokumen %d sedang diproses",q->items[q->head]);
  9. deleteQueue(q->items[q->head],q);
  10. }
  11. }
  12. return;
  13. }
  14.  
  15.  
  16. void deleteQueue(itemType *nItem,queue *q)
  17. {
  18. printf(" Inside deleteQueue -> head : %d\n ", q->head);
  19. q->head = (q->head + 1);
  20. return;
  21. }
  22.  
Mar 21 '07 #1
Share this Question
Share on Google+
1 Reply


DeMan
100+
P: 1,806
Basically, the compiler expects a pointer to itemType to be passed during the function. a pointer is an int, so the compiler recognises that you might deliberately be passing an integer but would like a cast to assure it that you really do intend passing that pointer intend.
A cast is acheived, by preceding the variable (in this case) with
(itemType *)
eg
Expand|Select|Wrap|Line Numbers
  1. deleteQueue((itemType *)q->items[q->head],q);
  2.  
if, however, the object at q->items[q->head] is of type itemType (and just happens to be compatible with an integer, you should pass a reference to it
viz:
Expand|Select|Wrap|Line Numbers
  1. deleteQueue(&(q->items[q->head]),q);
  2.  
you may like to be sure which of these you want to do, becauswe the one you don't will probably give you interesting side-efefects
Mar 21 '07 #2

Post your reply

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