Results 1 to 3 of 3

Thread: GNU C++ struct _attribute_ packed...compile error

  1. #1
    Join Date
    Feb 2013
    Beans
    2

    Question GNU C++ struct _attribute_ packed...compile error

    I'm having difficulty correcting the following compile error.
    Any help would be appreciated.

    Source.....

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdint.h>
    using namespace std;

    struct strA
    { char a;
    int b;
    } _attribute_ ((packed,aligned (8)));

    int main(int argc, char **argv)
    {
    int mainrc=0;
    return mainrc;
    }

    Compiler.......

    g++ --version
    g++ (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2
    Copyright (C) 2012 Free Software Foundation, Inc.

    ERROR.........

    g++ -std=c++11 /home/arcdeveloper/csrc/structatt.c++
    /home/arcdeveloper/csrc/structatt.c++:9:17: error: ‘packed’ was not declared in this scope
    /home/arcdeveloper/csrc/structatt.c++:9:34: error: ‘aligned’ was not declared in this scope

    Thanks in advance, gtyler

  2. #2
    Join Date
    Apr 2009
    Location
    Germany
    Beans
    2,134
    Distro
    Ubuntu Development Release

    Re: GNU C++ struct _attribute_ packed...compile error

    its __attribute__ with two underscores

    what are you trying to archive here? a char followed by a 8 byte aligned int?

    that would be written like this:
    Code:
     struct strA
     { char a ;
     int b __attribute__((aligned (8)));
     } __attribute__((packed));
    but the structure will still be 16byte large, I think you need to use explicit padding to get it to 12 byte.
    Last edited by MadCow108; February 17th, 2013 at 12:10 PM.

  3. #3
    Join Date
    Feb 2013
    Beans
    2

    Re: GNU C++ struct _attribute_ packed...compile error

    Thanks MADCOW108.

    My eyes must not be what they used to be.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •