__attribute__ in C programing - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

__attribute__ in C programing

DeepakDeepak Posts: 5Member
Does anybody know what the __attribute__ in certain .c and .h files in Linux means?
Know where I can get additional info?

Thanks,
Deepak

Comments

  • gautamgautam Posts: 642Member
    I have never seen __attribute__ in a c or .h file, is this in a program ? or is this in the standard gcc header files ? If its in a program, look into the code, and check.

    : Does anybody know what the __attribute__ in certain .c and .h files in Linux means?
    : Know where I can get additional info?
    :
    : Thanks,
    : Deepak
    :


  • DeepakDeepak Posts: 5Member
    : I have never seen __attribute__ in a c or .h file, is this in a program ? or is this in the standard gcc header files ? If its in a program, look into the code, and check.
    :
    : : Does anybody know what the __attribute__ in certain .c and .h files in Linux means?
    : : Know where I can get additional info?
    : :
    : : Thanks,
    : : Deepak
    : :
    :
    :

    Do a grep for __attribute__ in the source files of Linux components.

    D


  • DeepakDeepak Posts: 5Member
    : : I have never seen __attribute__ in a c or .h file, is this in a program ? or is this in the standard gcc header files ? If its in a program, look into the code, and check.
    : :
    : : : Does anybody know what the __attribute__ in certain .c and .h files in Linux means?
    : : : Know where I can get additional info?
    : : :
    : : : Thanks,
    : : : Deepak
    : : :
    : :
    : :
    :
    : Do a grep for __attribute__ in the source files of Linux components.
    :
    : D
    :
    :

    Check out http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC84

    D


  • gautamgautam Posts: 642Member
    Thank you,

    Actually I was searching for this sort of stuff for my code in C, and was wondering what the option was for compiling in 1byte boundary.

    : : : I have never seen __attribute__ in a c or .h file, is this in a program ? or is this in the standard gcc header files ? If its in a program, look into the code, and check.
    : : :
    : : : : Does anybody know what the __attribute__ in certain .c and .h files in Linux means?
    : : : : Know where I can get additional info?
    : : : :
    : : : : Thanks,
    : : : : Deepak
    : : : :
    : : :
    : : :
    : :
    : : Do a grep for __attribute__ in the source files of Linux components.
    : :
    : : D
    : :
    : :
    :
    : Check out http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC84
    :
    : D
    :
    :


  • ertzogertzog Posts: 6Member
    : Does anybody know what the __attribute__ in certain .c and .h files in Linux means?

    : Know where I can get additional info?



    It is quite easy: info gcc.

    The keyword __attribute__ ((lalala)) tells gcc,

    that function is not just a common function. It can make

    many different things with it, due the lalala.

    Read the section "C extensions"->"Function attributes"


  • aliancemdaliancemd Posts: 4Member
    The article is since 2001 but I will answer anyway.

    Take for example this code:
    [code]
    struct Packaging {
    char c;
    int i;
    } Packaging;

    sizeof(Packaging) will be 8 Bytes.
    [/code]
    or you could do:
    [code]
    #pragma pack(push)
    #pragma pack(1)

    struct Packaging {
    char c;
    int i;
    } Packaging;

    #pragma pack(pop)

    sizeof(Packaging) will be 5 Bytes because of aliasing.
    [/code]
    We can use __attribute__ instead of #pragma, like this:
    [code]
    struct Packaging {
    char c;
    int i;
    } __attribute__((packed)) Packaging;
    [/code]
    It will have the same effect as pragma.
    And there are a lot of other uses for __attribute__.
  • hyphentechhyphentech Posts: 3Member
    Hi,

    I have just noticed that all my files have the attribute C. I've been running XP on the machine for several years, and I never noticed that before.


    [link=http://www.hyphentechnologies.in/website-designing.php]Website Design Company[/link] | [link=http://www.hyphentechnologies.in/graphic-designing.php]Graphics Design Services[/link]
  • hyphentechhyphentech Posts: 3Member
    Hi,

    I have just noticed that all my files have the attribute C. I've been running XP on the machine for several years, and I never noticed that before.


Sign In or Register to comment.