9

This sounds like something I should be able to Google, but I can't find a good reference. What exactly does __attribute__((force)) do? As in:

 return (__attribute__((force)) uint32_t) *p

(this is for an ARM system, cross compiled with clang, but I can't find any reference anywhere on this attribute even in clang/arm specific pages..).

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
HardcoreHenry
  • 5,909
  • 2
  • 19
  • 44

1 Answers1

9

__attribute__((force)) is used to suppress warnings in sparse, the c semantics checker of the linux kernel.

The wikipedia article of sparse lists the following attributes as defined by sparse:

  • address_space(num)
  • bitwise
  • force
  • context(expression,in_context,out_context)

If you need more information about these, you can take a look at the man page of sparse

In the linux kernel some these attributes are redefined in linux/include/linux/compiler_types.h. For example __force expands to __attribute__((force)) or __bitwise to __attribute__((bitwise)).

However the linux documentation about sparse tells us, that gcc ignores these attributes:

And with gcc, all the “__bitwise”/”__force stuff” goes away, and it all ends up looking just like integers to gcc.

kalehmann
  • 4,821
  • 6
  • 26
  • 36