Basic C language in mbed question

17 Jun 2010

Hi:

Not being the strongest programmer in C, I often search for code examples for things that I want to do in order to see how others have implemented.

I often come across signed and unsigned variables and I can't seem to make use of the code on the mbed.  I have had limited success in converting these and usually end up creating more problems with mixed data types than I can get myself out of.

Can I use u08, s08, u16 as written in functions, or do I need to set them as something else?

For example:

void sta013GetMP3Info(u16 *bitrate, u08 *sampFreq, u08 *mode)
 {
     u08 headL, headM, headH;
     u08 mpegID, bitrateIndex, sampFreqIndex;
This is a partial copy out of some MP3 code I am looking at that is using an STA013 decoder.

Can I write something at the beginning of my code that says U16 = unsigned 16 bit mbed variable and how is "unsigned 16 bit mbed variable" declared?

If there is documentation for this, please point me to it.

Thanks

Tim

17 Jun 2010

If you really need exact-sized variables (e.g. reading/writing packed data), you can use the following types: uint8_t, uint16_t, uint32_t. However, it is much better for the performance to use the native-sized integers (int, unsigned int). On mbed they're 32 bit long and so should cover most of your needs.

17 Jun 2010

Hi Igor:

Thank you,  So, if I just specify signed or unsigned int according to whether it is listed as one or the other I should be ok?

What if they have defined the variable to represent a register in a device?  I don't have an example in mind but it seems to me I am dealing with registers all the time, whether to set options or read status and so on.  In those cases should I use the forms that you have provided in your previous note?

Thanks

Tim