The difference between GNU C and ANSI C

Source: Internet
Author: User

Reference: http://tsroad.lofter.com/post/376316_57ac519

1.GNU C defines a 0-length array, which is intended to define variable-length structures.

struct VAR_STRUCT
{
int Len;
Char data[0];
};

The data of this structure is immediately followed and can be accessed using Data[index].

2.case can range match, case x...y

Switch (n)
{
Case 0...9 C=1;break;
Case 10...11 C=2;break;
...
}


3.GNU c the statement in curly braces as an expression that can appear where any expression can appear

#define Int_min (x, y) \
{int __x= (x); int __y= (y); __x<__y?__x:__y;}


4.typeof keyword, you can get the type of the variable

int x;
typeof (x) y;


5. Macros that support variable parameters

#define DPRINT (Fmt,arg ...) \
PRINTK (fmt,# #arg)


6. Current function name, using macro __function__

7. When initializing a struct or array, the initialization values are allowed to appear in any order by index and struct name.

int s[5]={[0 ... 3]=3,[4]=1};

Note [0 spaces ... Space 3]

struct X
{
int A;
Char b;
};
struct x y=
{
. b= ' h ',
. a=10,
};



8. Allows the declaration of functions, variables, types of special properties, as long as the following add __atribute__ ((attribute))

#define Attri_noreturn __attribute__ ((noreturn))

void exit () Attri_noreturn
{
...
}


9.GNU C provides a large number of built-in functions

10. Use the Do ... while (0) to define the macro to facilitate the addition of the macro;

#define XXX Do{free (p);p =null;} while (0)


11. Error handling is often done with goto statements.

The above is from "Linux device driver development details".

The difference between GNU C and ANSI C

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.