Thread: Manually reading an integer literal

  1. #16
    misoturbutc Hodor's Avatar
    Join Date
    Nov 2013
    Posts
    1,791
    Quote Originally Posted by awsdert View Post
    You'll see in my folowing post in a minute, just look for 'void printNum'.
    Yeah, I still can't see why you're trying to hide details using typedef. In this:

    Code:
    int rdNum( int_c_pvoid_t getchr, void *source, int c, num_out_t *out )
    c_pvoid_t getchr means nothing to me (what is a c_pvoid_t?) and I have to look around in the code to try and work it out when you could just have it right there as a function pointer and I wouldn't have to go searching. Why? I honestly cannot see the benefit of this.

    Some asides:
    1) If you must use a typedef (and in this case I think you don't because it's, in my opinion, damaging) it's probably a good idea not to use the suffix _t because POSIX reserves that. It's asking for trouble.
    2) I'd get rid of the nested functions; the code is barely readable. It's a convoluted mess to be quite honest
    3) What is the point of the BASE_NUM, BASE_a2z etc directives when all you use them for is declaring some string constants? (which should probably have static linkage and be const qualified anyway)
    4) Are you writing C in this manner because you think the executable will be faster? Premature optimisation is the root of all evil

    I'm sure you have reasons for everything I've pointed out, but if I was handed this code to maintain I'd, honestly, throw it out and start again. I can't understand what it's doing and there's no reason -- that I can see -- for writing it this way.

    Anyhow, good luck. Hopefully someone with more skill than me can give more constructive critique

  2. #17
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    still at work so will make it short, compare fgetc, my function sgetc and how getchr is used and you should be able to connect the dots, I'll check back after work

  3. #18
    Registered User awsdert's Avatar
    Join Date
    Jan 2015
    Posts
    1,733
    k I'm back now, in case you still don't get it I was abstracting away unneeded information, a function that reads integer literals should at no point need to know where characters fed to it are coming from, only what the next character is and whether to use it or return it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. byte array plus integer literal question
    By pauljcx in forum C Programming
    Replies: 2
    Last Post: 08-04-2011, 01:31 PM
  2. Reading integer from string
    By dr_kaufman in forum C Programming
    Replies: 2
    Last Post: 04-30-2011, 09:40 AM
  3. Reading an integer from file
    By 843 in forum C Programming
    Replies: 18
    Last Post: 11-27-2010, 07:43 AM
  4. Reading integer from file.
    By esben in forum C Programming
    Replies: 4
    Last Post: 03-04-2006, 12:39 PM
  5. Appended integer literal to std::string
    By Tonto in forum C++ Programming
    Replies: 7
    Last Post: 07-30-2005, 11:49 AM

Tags for this Thread