GIDForums  

Go Back   GIDForums > Computer Programming Forums > C Programming Language
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 28-Mar-2005, 20:26
lung_sen lung_sen is offline
New Member
 
Join Date: Mar 2005
Posts: 2
lung_sen is on a distinguished road
Unhappy

passing arg 1 of `write' makes integer from pointer withouta cast


Hi, I encounter this problem, where there are 10 warnings for every read/write operation I've done. I'm using GCC compiler to compile it. Here is my code. As far as I know, it means that the first argument (char*)&ConfValue need to be integer, but It was works in another code, declared as char. I really dont know how to debug it.
Anyone can help me? Thank you
  #2  
Old 28-Mar-2005, 20:31
lung_sen lung_sen is offline
New Member
 
Join Date: Mar 2005
Posts: 2
lung_sen is on a distinguished road
Hi this is the code, spicode.doc. Pls take a look. Thank u
Attached Files
File Type: doc spicode.doc (36.5 KB, 12 views)
  #3  
Old 28-Mar-2005, 21:10
nkhambal nkhambal is offline
Regular Member
 
Join Date: Jul 2004
Location: CA USA
Posts: 313
nkhambal is a jewel in the roughnkhambal is a jewel in the rough
Hi,

You have confused between "fopen" and "open".
open returns file descriptor for the opened file which is an integer. You are casting it to be a pointer. It is wrong. "fopen" returns pointer not "open"
CPP / C++ / C Code:
 FILE *fd;

    if( (fd =(FILE *) open("/dev/spi",O_RDWR)) < 0)
    {
        printf("Error opening fd=%d\n",fd);
        exit(1);
    }

should be

CPP / C++ / C Code:

int fd;

    if( (fd = open("/dev/spi",O_RDWR)) < 0)
    {
        printf("Error opening fd=%d\n",fd);
        exit(1);
    }

So is the problem with read() and write(). They expect first argument to be an integer file descriptor "fd" where as you are passing a pointer "fd". Hence the warnings.

Correcting above "open" code should supress all the warnings.
 
 

Recent GIDBlogDeveloping GUIs with wxPython (Part 3) by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
2D arrays:dynamic allocation and freeing bravetanveer C Programming Language 48 27-Nov-2007 15:55
Passing referance and passing pointer Poolan C++ Forum 6 29-Oct-2004 07:18

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 07:11.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.