Thread: Anything wrong with this(char to short and int)

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    7

    Question Anything wrong with this(char to short and int)

    I have made some handy things since i have to read words and dwords often but i think something is wrong with them
    could someone tell me what is wrong with them
    Code:
    //these do NO checking so to figure out if there was an eof try if( rety=(EOF<<8 | EOF)){end of file
    //but you might need some type mods
    unsigned short int getword(FILE *fp){
    	unsigned short int rety;
    	rety=(getc(fp)<<8) | getc(fp);
    	//tmp[0]
    	return rety;
    }
    //no checking on this one either use this forumla
    //if( rety=((EOF<<8 | EOF)<<16)|(EOF<<8 | EOF) ){end of file; but you might need some type mods
    unsigned int getdword(FILE *fp){
    	unsigned int rety;
    	rety=(getword(fp)<<16) | getword(fp);
    	return rety;
    }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    EOF is a negative number. Overflow/underflow on signed integers is undefined.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Dec 2005
    Posts
    7
    hmmm didnt know that
    so how could I put eof in those functions

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read into an integer, test for EOF, if it isn't EOF, then do your assignment.


    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  3. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM