Re: typedefs and structs

From: linux-os (Dick Johnson) (
Date: 11/09/05

  • Next message: "Re: typedefs and structs"
    Date:	Wed, 9 Nov 2005 15:26:10 -0500
    To: "linas" <>

    On Wed, 9 Nov 2005, linas wrote:

    > On Wed, Nov 09, 2005 at 08:22:15AM -0800, Vadim Lobanov was heard to remark:
    >> On Wed, 9 Nov 2005, J.A. Magallon wrote:
    >>> void do_some_stuff(T& arg1,T& arg2)
    >> A diligent C programmer would write this as follows:
    >> void do_some_stuff (struct T * a, struct T * b);
    >> So I don't see C++ winning at all here.
    > I guess the real point that I'd wanted to make, and seems
    > to have gotten lost, was that by avoiding using pointers,
    > you end up designing code in a very different way, and you
    > can find out that often/usually, you don't need structs
    > filled with a zoo of pointers.

    But you can't avoid pointers unless you make your entire
    program have global scope. That may be great for performance,
    but a killer if for have any bugs.

    Procedures that get pointers to variables (including structures)
    are a way of isolating faults. Without them, you can't test
    the procedures in a working environment.

    Also, without pointers, you are severely limited on the kinds
    of libraries you can share. You certainly wouldn't want
    to compile an entire C runtime library into your code so
    that all the buffers have local scope.

    > Minimizing pointers is good: less ref counting is needed,
    > fewer mallocs are needed, fewer locks are needed
    > (because of local/private scope!!), and null pointer
    > deref errors are less likely.

    No. Minimizing pointers should not be an objective. Properly
    using the components of your tool-set should be. This means
    that you use the correct access mode for various object
    types. "Correct" depends upon the instant context, not upon
    some company or personal rule.

    > There are even performance implications: on modern CPU's
    > there's a very long pipeline to memory (hundreds of cycles
    > for a cache miss! Really! Worse if you have run out of
    > TLB entries!). So walking a long linked list chasing
    > pointers can really really hurt performance.

    Linked lists are some of the necessary elements when one
    doesn't know ahead of time the number of objects that must
    be manipulated. They are just programming tools. You use
    them when they are necessary. The fact that they use pointers
    to make the links is not relevant.

    > By using refs instead of pointers, it helps you focus
    > on the issue of "do I really need to store this pointer
    > somewhere? Will I really need it later, or can I be done
    > with it now?".

    Huh? References (at the opcode level) are pointers. There
    is no difference whatsoever. For memory references, you
             direct, direct+displacement, register_indirect,

    There isn't anything else. Some processors let you sum
    displacements over several registers. Nevertheless, that's
    all you have. Accessing a variable by reference is an
    old artifact of FORTRAN. It can be efficient if the
    architecture is flat and global so the compiler can
    substitute direct access. In other words, no parameter
    or pointer actually gets passed to the routine. The
    compiler just remembers what the parameters actually
    were and substitutes code to directly access the

    Not so in C++. With C++, "reference" is a user-shorthand
    where the compiler actually accesses variables with pointers.
    The rules don't prohibit C++ compilers from using FORTRAN-
    like conventions for passing-by-reference. It's just that
    nobody seems to do so.

    > I don't know if the idea of "using fewer pointers" can
    > actually be carried out in the kernel. For starters,
    > the stack is way too short to be able to put much on it.
    > --linas

    Dick Johnson
    Penguin : Linux version on an i686 machine (5589.55 BogoMips).
    Warning : 98.36% of all statistics are fiction.

    The information transmitted in this message is confidential and may be privileged. Any review, retransmission, dissemination, or other use of this information by persons or entities other than the intended recipient is prohibited. If you are not the intended recipient, please notify Analogic Corporation immediately - by replying to this message or by sending an email to - and destroy all copies of this information, including any attachments, without reading or disclosing them.

    Thank you.
    To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
    the body of a message to
    More majordomo info at
    Please read the FAQ at

  • Next message: "Re: typedefs and structs"

    Relevant Pages

    • Re: IBM-MAIN Digest - 28 Mar 2014 to 29 Mar 2014 (#2014-88)
      ... Compiler error in z/OS C compiler ... Initializing of pointers inside structures (was: ... send email to listserv@xxxxxxxxxxxxxxx with the message: INFO IBM-MAIN ... Subject: Clist character string compare ...
    • Re: new IL: C (sort of...).
      ... only for "recent" Pascals, ... far pointers weren't really limited, ... in my compiler, I made wchar_t a builtin type (in most cases, aliased to ... I could very well include builtin "managed strings" in the new IL. ...
    • Re: new IL: C (sort of...).
      ... and the frontend compiler needs to be able ... Having very limited pointers is a fact of life in a VM language though, ... vague claims about Pascal's pointer support. ... That is pretty normal for standards (the ...
    • Re: code optimiation
      ... Given that the compiler can often optimise the generated code to use the best sized types available, it's seldom worth specifying "fast" types explicitly. ... pointers and floating point types whose "zero value" might not be all- ... instruction, so the assembler produced for *p++ when used as the ... It will do the same job, and let you write the source code using proper array constructs. ...
    • Re: A taxonomy of types
      ... I am describing how to represent the representation (and, ... if the system follows static typing rules (such as in a compiler), ... so, the hardware sees pointers and pointer arithmetic, but the compiler ... "Besides the char types, up to three sizes of integer, declared short int, ...