Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #9348

Re: What is the use of ':' in type definition?

From Eric Sosman <esosman@ieee-dot-org.invalid>
Newsgroups comp.lang.c
Subject Re: What is the use of ':' in type definition?
Date 2011-08-13 10:57 -0400
Organization A noiseless patient Spider
Message-ID <j263j2$uq9$1@dont-email.me> (permalink)
References <a46e730f-78dc-4188-b837-71b3221a68fa@k15g2000yqd.googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

What is the use of ':' in type definition? fl <rxjwg98@gmail.com> - 2011-08-13 06:49 -0700
  Re: What is the use of ':' in type definition? Nobody <nobody@nowhere.com> - 2011-08-13 15:10 +0100
  Re: What is the use of ':' in type definition? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 10:57 -0400
    Re: What is the use of ':' in type definition? "Aaron W. Hsu" <arcfide@sacrideo.us> - 2011-08-13 14:28 -0400
      [OT] Re: What is the use of ':' in type definition? Eric Sosman <esosman@ieee-dot-org.invalid> - 2011-08-13 17:39 -0400
  Re: What is the use of ':' in type definition? "Heinrich Wolf" <invalid@invalid.invalid> - 2011-08-13 17:40 +0200

csiph-web