GCC Extensions for C languages

Source: Internet
Author: User
Tags deprecated

The GNU compiler (GCC) provides a number of C language extensions that the compiler uses to generate more efficient machine code.

inline functions

Static int foo (void/** /}


Avoid inline

int foo (void/*... ) */ }


Pure function

int foo (int/* /}

The return value is only affected by function arguments or nonvolatile global variables.

Constant function

__ATTRIBUTE__ ((constint foo (int/* ... */ }

The constant function is a strict pure function. The constant function cannot access the global variable, and the parameter cannot be a pointer type. Therefore, the return value of a constant function is only related to the value of the parameter passed by the value.

function with no return value

void foo (int/* ...) */ }

Functions that allocate memory

__attribute__ (mallocvoid *copy (   ) {int);    return malloc (ten);}

Forcing callers to check the return value

1#include <stdio.h>2 3__attribute__ ((Warn_unused_result))intfoo ()4 {5     return 0;6 }7 8 intMain ()9 {Ten foo (); One     return 0; A}


Identify the function as "Deprecated (deprecated)"

void foo (void/*... ) */ }


Identify the function as being used

Static void foo (void/*... ) */ }


Identifies a function or parameter as unused

int foo (int/* ...) */}


Compact Storage (pack) for structures

struct __attribute__ ((packed)) Foo {...};

The packed property tells the compiler that a type or variable should be stored in memory compactly, using as little space as possible, and may not rely on alignment requirements. If you specify this property on a struct (struct) or union (union), you need to store all the variables compactly. If you specify this property only for a variable, only the specific variable is stored compactly.

GCC Extensions for C languages

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.