structure paddind

Discussion in 'C Programming' started by amit, Mar 5, 2008.

  1. amit

    amit Guest

    how to stop or change structure padding ???
    amit, Mar 5, 2008
    #1
    1. Advertising

  2. amit

    Chris Dollin Guest

    amit wrote:

    > how to stop or change structure padding ???


    (a) See your local implementation manual for the implementation-specific
    way to do this.

    (b, preferred if plausible) Write your code so that it doesn't care about
    structure padding even if there is any.

    Why do you think you want to stop or change structure padding?

    --
    "Well begun is half done." - Proverb

    Hewlett-Packard Limited Cain Road, Bracknell, registered no:
    registered office: Berks RG12 1HN 690597 England
    Chris Dollin, Mar 5, 2008
    #2
    1. Advertising

  3. amit

    jacob navia Guest

    Chris Dollin wrote:
    > amit wrote:
    >
    >> how to stop or change structure padding ???

    >
    > (a) See your local implementation manual for the implementation-specific
    > way to do this.
    >
    > (b, preferred if plausible) Write your code so that it doesn't care about
    > structure padding even if there is any.
    >
    > Why do you think you want to stop or change structure padding?
    >


    We had a discussion about the

    #pragma pack

    construct in this group several weeks ago. Google for it, since
    we gave a detailed discussion about that construct in many different
    situations and compilers

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Mar 5, 2008
    #3
  4. amit

    Chris Dollin Guest

    jacob navia wrote:

    > Chris Dollin wrote:
    >> amit wrote:
    >>
    >>> how to stop or change structure padding ???

    >>
    >> (a) See your local implementation manual for the implementation-specific
    >> way to do this.
    >>
    >> (b, preferred if plausible) Write your code so that it doesn't care about
    >> structure padding even if there is any.
    >>
    >> Why do you think you want to stop or change structure padding?

    >
    > We had a discussion about the
    >
    > #pragma pack
    >
    > construct in this group several weeks ago. Google for it, since
    > we gave a detailed discussion about that construct in many different
    > situations and compilers


    Regardless of any historical discussion about #pragmapack, I'd still
    like to hear the OP's reasons, since their concerns might be satisfiable
    without recourse to semi-portable assistance (deLameters should be enough).

    --
    "Well begun is half done." - Proverb

    Hewlett-Packard Limited Cain Road, Bracknell, registered no:
    registered office: Berks RG12 1HN 690597 England
    Chris Dollin, Mar 5, 2008
    #4
  5. amit

    CBFalconer Guest

    jacob navia wrote:
    > Chris Dollin wrote:
    >> amit wrote:
    >>
    >>> how to stop or change structure padding ???

    >>
    >> (a) See your local implementation manual for the
    >> implementation-specific way to do this.
    >>
    >> (b, preferred if plausible) Write your code so that it doesn't
    >> care about structure padding even if there is any.
    >>
    >> Why do you think you want to stop or change structure padding?

    >
    > We had a discussion about the #pragma pack construct in this
    > group several weeks ago. Google for it, since we gave a detailed
    > discussion about that construct in many different situations and
    > compilers


    Once more, Jacob is off-topic and not portable. See the following
    extract from N869:

    6.10.6 Pragma directive

    Semantics

    [#1] A preprocessing directive of the form

    # pragma pp-tokens-opt new-line

    where the preprocessing token STDC does not immediately
    follow pragma in the directive (prior to any macro
    replacement)136) causes the implementation to behave in an
    implementation-defined manner. The behavior might cause
    translation to fail or cause the translator or the resulting
    program to behave in a non-conforming manner. Any such
    pragma that is not recognized by the implementation is
    ignored.

    ____________________

    136An implementation is not required to perform macro
    replacement in pragmas, but it is permitted except for in
    standard pragmas (where STDC immediately follows pragma).
    If the result of macro replacement in a non-standard
    pragma has the same form as a standard pragma, the
    behavior is still implementation-defined; an
    implementation is permitted to behave as if it were the
    standard pragma, but is not required to.


    [#2] If the preprocessing token STDC does immediately follow
    pragma in the directive (prior to any macro replacement),
    then no macro replacement is performed on the directive, and
    the directive shall have one of the following forms whose
    meanings are described elsewhere:

    #pragma STDC FP_CONTRACT on-off-switch
    #pragma STDC FENV_ACCESS on-off-switch
    #pragma STDC CX_LIMITED_RANGE on-off-switch

    on-off-switch: one of
    ON OFF DEFAULT

    --
    [mail]: Chuck F (cbfalconer at maineline dot net)
    [page]: <http://cbfalconer.home.att.net>
    Try the download section.


    --
    Posted via a free Usenet account from http://www.teranews.com
    CBFalconer, Mar 5, 2008
    #5
  6. jacob navia <> writes:
    > Chris Dollin wrote:
    >> amit wrote:
    >>> how to stop or change structure padding ???

    >>
    >> (a) See your local implementation manual for the implementation-specific
    >> way to do this.
    >>
    >> (b, preferred if plausible) Write your code so that it doesn't care about
    >> structure padding even if there is any.
    >>
    >> Why do you think you want to stop or change structure padding?

    >
    > We had a discussion about the
    >
    > #pragma pack
    >
    > construct in this group several weeks ago. Google for it, since
    > we gave a detailed discussion about that construct in many different
    > situations and compilers


    As you know, and as the OP perhaps doesn't know, #pragma pack is not
    defined by the standard, is implemented differently by different
    implementations, is not implemented at all by other implementations,
    and will necessarily make any code that uses it non-portable (unless
    all uses of it are protected by #ifdef).

    Using #pragma pack might turn out to be the perfect solution to the
    OP's problem, but recommending it without even mentioning the caveats
    is irresponsible.

    And of course it can cause struct members to be misaligned, which can
    slow down access to such members.

    Depending on what the OP is trying to do, reordering the member
    declarations so the larger members are declared first might solve the
    problem without any of the drawbacks of #pragma pack.

    See also question 2.12 in the comp.lang.c FAQ,
    <http://www.c-faq.com/>, and follow the links to other relevant
    questions. <http://www.c-faq.com/struct/align.esr.html> has some good
    information.

    --
    Keith Thompson (The_Other_Keith) <>
    Nokia
    "We must do something. This is something. Therefore, we must do this."
    -- Antony Jay and Jonathan Lynn, "Yes Minister"
    Keith Thompson, Mar 5, 2008
    #6
  7. In article <>,
    Keith Thompson <> wrote:

    >Using #pragma pack might turn out to be the perfect solution to the
    >OP's problem, but recommending it without even mentioning the caveats
    >is irresponsible.


    He pointed the poster to a previous discussion of it. Does he have
    to repeat it all too?

    -- Richard
    --
    :wq
    Richard Tobin, Mar 5, 2008
    #7
  8. amit

    jacob navia Guest

    Richard Tobin wrote:
    > In article <>,
    > Keith Thompson <> wrote:
    >
    >> Using #pragma pack might turn out to be the perfect solution to the
    >> OP's problem, but recommending it without even mentioning the caveats
    >> is irresponsible.

    >
    > He pointed the poster to a previous discussion of it. Does he have
    > to repeat it all too?
    >
    > -- Richard


    It was a deep discussion with pros, cons, examples
    from weird architectures, etc. I did not recommend anything
    I just pointed to that discussion, as you say.

    --
    jacob navia
    jacob at jacob point remcomp point fr
    logiciels/informatique
    http://www.cs.virginia.edu/~lcc-win32
    jacob navia, Mar 5, 2008
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Excluded_Middle

    Pointers to structure and array of structure.

    Excluded_Middle, Oct 24, 2004, in forum: C Programming
    Replies:
    4
    Views:
    740
    Martin Ambuhl
    Oct 26, 2004
  2. Leo Nunez
    Replies:
    3
    Views:
    1,192
    Neil Kurzman
    Feb 9, 2005
  3. Replies:
    2
    Views:
    592
  4. Replies:
    9
    Views:
    25,242
    Lal Bahadur Singh
    Nov 11, 2011
  5. meisterbartsch
    Replies:
    2
    Views:
    766
    meisterbartsch
    Jun 12, 2007
Loading...

Share This Page