This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Does C2000 compiler 6.1.0 support packed structure?



Hi,

When I read the manual of C2000 compiler 6.1.0, it said that packed structure is supported.  However, it does not work. And there is a wiki page said that packed structure is not supported by C2000.

Does anyone know if this feature is available at all?

Thanks!

Ren

  • Make sure you are using the --gcc option.  Supposing this doesn't help ...

    Ren You said:
    Does anyone know if this feature is available at all?

    Yes.  It is available.

    Ren You said:
    However, it does not work.

    Please show an example which doesn't work.  We need to build it ourselves, so please include all the required source, and the exact build options you used.  Please be clear about why it does not work.  

    Thanks and regards,

    -George

  • 5468.test.zip

    Thanks for the reply.  I am pretty sure -gcc is used.  The compiler rejects the __packed__ attribute and reports an error.

    I attached a very simple test project.

    Ren

    // main.c ---

    #include <stdio.h>

    struct __attribute__((__packed__)) _my_struct
    {
    char x;
    unsigned long y;

    unsigned long a:8;
    unsigned long b:8;
    unsigned long c:8;
    unsigned long d:8;
    };

    /*
    * hello.c
    */
    int main(void) {
    //printf("Hello World!\n");

    struct _my_struct t = {0};

    t.a = 1;
    t.b = 2;
    t.c = 3;
    t.d = 4;


    return 0;
    }

    Compiled result:

    **** Build of configuration Debug for project test ****

    "C:\\ti\\ccsv5\\utils\\bin\\gmake" -k all
    'Building file: ../hello.c'
    'Invoking: C2000 Compiler'
    "C:/ti/ccsv5/tools/compiler/c2000_6.1.0/bin/cl2000" -v28 -ml -mt -g --include_path="C:/ti/ccsv5/tools/compiler/c2000_6.1.0/include" --relaxed_ansi --gcc --diag_warning=225 --display_error_number --preproc_with_compile --preproc_dependency="hello.pp" "../hello.c"
    "../hello.c", line 3: error #1167: invalid attribute for "struct _my_struct"
    "../hello.c", line 20: warning #552-D: variable "t" was set but never used
    1 error detected in the compilation of "../hello.c".

    >> Compilation failure
    gmake: *** [hello.obj] Error 1
    gmake: Target `all' not remade because of errors.

    **** Build Finished ****

  • This was an error in the documentation.  The packed support information was only supposed to be included in the guides for the relevant targets but was included in the C2000 guide by mistake.  This should have already been fixed for future versions of the guide.

    There is no packed support for C2000.  Note that words (smallest addressable units) are 16-bits on C2000, which is the same as char and int size, and is already the default alignment.

  • Sorry, I didn't look at your code above-- longs are 32-bit aligned, so there will still be padding in your struct.