Thread: Other then uint8_t what is the other alternative we can use in c compller

  1. #1
    Registered User
    Join Date
    Apr 2013
    Posts
    3

    Other then uint8_t what is the other alternative we can use in c compller

    I need to assign the port pins to 0 to 15 binary bits,as i'm using c compiler it's not compiling the following code,even though i have added the stdint.h header file,so is any other way i can compile this...
    uint8_t v
    Last edited by angiey; 04-24-2013 at 01:10 AM. Reason: I want to post my code which is giving me error..but after trying to post the code between[code][\code] i got error..

  2. #2
    Registered User
    Join Date
    Apr 2013
    Posts
    1,658
    What machine and what compiler are you using? 0 to 15 bits seems like you'd want a 16 bit unsigned integer, not an 8 bit one. On your compiler, how many bits are there in an "unsigned short"?

  3. #3
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Did you also compile under the C99 standard? Depending on the compiler, the steps needed will be different. stdint.h is not a header in older standards. For gcc the switch you need to flip is -std=c99, then you should have it.

    Or you can use char, which is guaranteed to be 1 byte.

  4. #4
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    uint8_t is a 8 bit number, not 16. You probably want uint16_t
    Fact - Beethoven wrote his first symphony in C

  5. #5
    Registered User
    Join Date
    Apr 2013
    Posts
    3
    Quote Originally Posted by rcgldr View Post
    What machine and what compiler are you using? 0 to 15 bits seems like you'd want a 16 bit unsigned integer, not an 8 bit one. On your compiler, how many bits are there in an "unsigned short"?
    I'm using Keil IDE...Maximum 16 bits,and i mean to say 0 to 15 binary dig[0000-1111]..
    Last edited by angiey; 04-24-2013 at 01:28 AM.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Assuming compilation under C99 or later, support of uintN_t (N = 8, 16, 32, 64) types by an implementation is optional.

    It strikes me as strange trying to use uint8_t to represent something that is 16 bits, rather than a uint16_t. Presumably an array of two of them .....


    Assuming a digital target machine (), the unsigned char type will always be implemented with at least eight bits.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    I think you're all misinterpreting him. He seems to mean a 4-bit quantity. I.e enough to represent 0 to 15.

    Just add this to an appropriate header file:
    Code:
    typedef unsigned char uint8_t;
    Even better, use preprocessor macros which determine whether the #include stdint.h, or just use this typedef, so that it works everywhere. This is a common way to deal with code that needs to run across multiple compilers.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by iMalc View Post
    I think you're all misinterpreting him. He seems to mean a 4-bit quantity. I.e enough to represent 0 to 15.
    The wording "I need to assign the port pins to 0 to 15 binary bits" articulates a need for 16 bits. If that is not the meaning, it is because the OP misstated the goal.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Right yeah sorry, I do think the goal certainly was misstated originally. It is hard to interpret strangely worded descriptions with the correct intent.
    Post #5 clarified it somewhat though.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. uint8_t to uint64_t
    By GeNcO in forum C Programming
    Replies: 5
    Last Post: 10-06-2011, 12:50 AM
  2. Regarding uint8 and uint8_t
    By icoigo in forum C Programming
    Replies: 1
    Last Post: 12-02-2010, 01:55 AM
  3. 2 uint8_t to a uint16?
    By DavidDobson in forum C Programming
    Replies: 1
    Last Post: 02-26-2009, 06:40 AM
  4. tuncated uint8_t
    By Coens in forum C Programming
    Replies: 14
    Last Post: 11-24-2008, 07:57 AM
  5. bit shifting uint8_t
    By kdoggfunkstah in forum C++ Programming
    Replies: 8
    Last Post: 07-28-2006, 03:38 AM

Tags for this Thread