Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 564 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
#define FOO 1u 2u 4u ... What does 1u and 2u mean?

#1
I'm working with the HCS12 MCU, and this was part of the library. I'm just wondering what
the 1U, 2U, 4U, 8U... means in this code. I'm still learning how to use classes, please try to explain things in layman terms.

My guess:
Does this just mean which bit is set as high?
1U = 00000001
2U = 00000010
...

What would this be called?

Thanks

typedef union {
byte Byte;
struct {
byte :1;
byte ADR1 :1; /* Slave Address Bit 1 */
byte ADR2 :1; /* Slave Address Bit 2 */
byte ADR3 :1; /* Slave Address Bit 3 */
byte ADR4 :1; /* Slave Address Bit 4 */
byte ADR5 :1; /* Slave Address Bit 5 */
byte ADR6 :1; /* Slave Address Bit 6 */
byte ADR7 :1; /* Slave Address Bit 7 */
} Bits;
struct {
byte :1;
byte grpADR_1 :7;
} MergedBits;
} IBADSTR;
extern volatile IBADSTR _IBAD @(REG_BASE + 0x000000E0UL);
#define IBAD _IBAD.Byte
#define IBAD_ADR1 _IBAD.Bits.ADR1
#define IBAD_ADR2 _IBAD.Bits.ADR2
#define IBAD_ADR3 _IBAD.Bits.ADR3
#define IBAD_ADR4 _IBAD.Bits.ADR4
#define IBAD_ADR5 _IBAD.Bits.ADR5
#define IBAD_ADR6 _IBAD.Bits.ADR6
#define IBAD_ADR7 _IBAD.Bits.ADR7
#define IBAD_ADR_1 _IBAD.MergedBits.grpADR_1
#define IBAD_ADR IBAD_ADR_1

#define IBAD_ADR1_MASK 2U
#define IBAD_ADR2_MASK 4U
#define IBAD_ADR3_MASK 8U
#define IBAD_ADR4_MASK 16U
#define IBAD_ADR5_MASK 32U
#define IBAD_ADR6_MASK 64U
#define IBAD_ADR7_MASK 128U
#define IBAD_ADR_1_MASK 254U
#define IBAD_ADR_1_BITNUM 1U

Reply

#2
They're just integer constants. The `U` suffix makes them unsigned ints instead of ints.

This is described in section 6.4.4.1 of the [final draft of the C11 standard]( ).
Reply

#3
It defines an unsigned integer [literal](

[To see links please register here]

). You can also see where they defined a hex literal to be an `unsigned long integer` by using `0x...UL`.

If you would like to know the bit pattern they produce, simply translate the decimal literals to their equivalent hex or binary literals. `1U` becomes `0x01U` and `01b`<sup>1</sup> in hex and binary respectively.

Another more commonly seen literal uses the `f`-suffix, that is a single precision floating point literal like `1.0f`.

<sub>1. for illustration only, not an actual literal per the standard</sub>
Reply

#4
In Embedded systems U literal means that the value is unsigned integer

you can find some usefull content here.

[information for Literals][1]


[1]:
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through