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


Groups > comp.lang.misc > #2197

Re: A good subset of C

From "Rod Pemberton" <dont_use_email@xnothavet.cqm>
Newsgroups comp.lang.misc
Subject Re: A good subset of C
Date 2014-05-05 18:57 -0400
Organization Aioe.org NNTP Server
Message-ID <op.xfesqctt6zenlw@localhost> (permalink)
References <lk7flm$m95$1@dont-email.me> <op.xfdw11vx6zenlw@localhost> <lk8nrc$ov4$1@dont-email.me>

Show all headers | View raw


On Mon, 05 May 2014 15:12:47 -0400, James Harris  
<james.harris.1@gmail.com> wrote:
> "Rod Pemberton" <dont_use_email@xnothavet.cqm> wrote in message  
> news:op.xfdw11vx6zenlw@localhost...

> But I cannot think how to bring in the definitions of structs
> (from which field offsets are calculated) without header files.

Well, I mentioned these:
address of - address operator & - part of C
sizeof() operator - part of C
typeof - part of the compilers
alignof - part of the compiler

But, I forgot this one:
offsetof() - part of C (macro in stddef.h)

offsetof() gets the offsets of something, like the element of a struct
or union.  Look at the macro in stddef.h or Google "offsetof macro".

Usually, they cast 0 or NULL as a pointer to a char or void as the
starting address of the appropriate type (struct or union), then
they subtract that from the address of a component, using the same
cast for the starting address, -> for component selection, & address
operator for the component's address, and a cast of the address to
a pointer to a char or void.

If you have a preprocessor, you can use it.  If not, I think you'll
have to insert an expanded definition everywhere you need it ...,
or perhaps implement it within the compiler.  The compiler should
have the necessary information to do it since it knows the struct
or union layout and sizes of everything in it's symbol tables etc.

> Could #if and friends be omitted, for example by including
> executable tests in the code?

#if #endif #ifdef could be replaced by regular if statements,
with a flag or variable to indicate which code is active.

#define's in the code can be replaced with the value or expanded
macro, etc.

I don't think there is an easy way to handle #include, except
cut-n-paste the entire include ...


Rod Pemberton

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


Thread

A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 08:47 +0100
  Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 10:56 +0100
    Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 19:41 +0100
      Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 21:08 +0100
        Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 21:58 +0100
          Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 22:55 +0100
            Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-06 00:01 +0100
              Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-06 00:44 +0100
          Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-06 09:45 +0100
  Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 07:33 -0400
    Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 19:14 +0100
    Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 20:12 +0100
      Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 18:57 -0400
        Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-07 11:55 +0100
          Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-07 19:04 -0400
            Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-08 10:14 +0100
              Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-08 07:35 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-08 16:22 +0100
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-09 16:45 -0400
                Re: A good subset of C "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-05-10 09:04 +0200
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-10 16:30 -0400
                Re: A good subset of C "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-05-11 11:59 +0200
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-11 11:06 -0400
                Re: A good subset of C Kaz Kylheku <kaz@kylheku.com> - 2014-05-12 00:26 +0000
                Re: A good subset of C "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de> - 2014-05-12 09:54 +0200
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-12 20:01 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-14 17:45 +0100
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-14 18:11 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-14 23:54 +0100
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-14 19:43 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-17 18:00 +0100
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-17 16:00 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-17 22:17 +0100
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-17 19:58 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-18 07:59 +0100
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-18 13:10 -0400
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-19 00:54 +0100
                Re: A good subset of C Andy Walker <news@cuboid.co.uk> - 2014-05-15 01:31 +0100
                Re: A good subset of C BGB <cr88192@hotmail.com> - 2014-05-14 23:43 -0500
                Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-17 18:38 +0100
                Re: A good subset of C Ian Collins <ian-news@hotmail.com> - 2014-05-25 11:04 +1200
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-24 20:36 -0400
                Re: A good subset of C Ian Collins <ian-news@hotmail.com> - 2014-05-25 12:53 +1200
                Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-24 21:34 -0400
                Re: A good subset of C Ian Collins <ian-news@hotmail.com> - 2014-05-25 14:11 +1200
                Re: A good subset of C Kaz Kylheku <kaz@kylheku.com> - 2014-05-25 06:47 +0000
                Re: A good subset of C Kaz Kylheku <kaz@kylheku.com> - 2014-05-25 06:43 +0000
  Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-05 20:59 +0100
    Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-05 22:28 +0100
      Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 18:57 -0400
        Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-06 00:26 +0100
      Re: A good subset of C George Neuner <gneuner2@comcast.net> - 2014-05-06 14:21 -0400
        Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-07 15:43 +0100
          Re: A good subset of C George Neuner <gneuner2@comcast.net> - 2014-05-07 16:03 -0400
            Re: A good subset of C "BartC" <bc@freeuk.com> - 2014-05-07 21:31 +0100
          Re: A good subset of C BGB <cr88192@hotmail.com> - 2014-05-07 15:41 -0500
    Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-05 18:46 -0400
      Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-06 00:42 +0100
        Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-06 06:48 -0400
          Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-07 15:40 +0100
            Re: A good subset of C "Rod Pemberton" <dont_use_email@xnothavet.cqm> - 2014-05-08 06:50 -0400
              Re: A good subset of C "James Harris" <james.harris.1@gmail.com> - 2014-05-08 15:43 +0100
                Re: A good subset of C George Neuner <gneuner2@comcast.net> - 2014-05-08 14:41 -0400
  Re: A good subset of C BGB <cr88192@hotmail.com> - 2014-05-05 19:08 -0500

csiph-web