Eric Sosman
8/13/2011 2:58:00 PM
On 8/13/2011 9:49 AM, fl wrote:
> Hi,
>
> I am reading a C source code generated from Matlab "coder generation
> tool", see below please.
>
>
> typedef struct {
> real_T Pv;
> real_T Rg;
> real_T cnt;
> uint_T is_c1_c4e : 4;
> uint_T is_active_c1_c4e : 1;
> } SFc1_c4eInstanceStruct;
>
>
> I do not understand the ':' in last two line definitions. I guess it
> is about 4 bytes, or 4X(16 bit word) alignment? Please tell me some
> because I do not use C a lot. Thanks.
Close -- but they're counting bits, not bytes. The is_c1_c4e
element uses four bits, and is_active_c1_c4e uses one. It looks
like the first can hold a value from 0 through 15, and the second
is probably a true-or-false flag indicating something about the
status of the first. Look up "bit field" (or "bit-field") in your
C textbook or reference.
As an aside, the output of a code generation tool is usually
not "source" from a human perspective, even if it's "source" to a
compiler. The true source is whatever you fed into the tool, and
that's the source you should probably be reading unless you're
trying to debug the tool itself.
(Very many years ago, someone asked for help debugging a truly
mystifying problem. I studied his source code, and the mysteries
just kept mounting up: I simply could not reconcile the output with
the code he showed me. Turned out he'd been putting his source
through the first phase of the compiler, hand-editing the assembly
"source" it generated, assembling and running the edited stuff, and
then bringing the original source to me for help. It's a good thing
there were no sharp implements close to hand when I figured out what
he'd been up to ...)
--
Eric Sosman
esosman@ieee-dot-org.invalid