64 lines
948 B
Plaintext
64 lines
948 B
Plaintext
Proprietary compiler extensions can be handy, but they commit you to always using that compiler. This rule raises an issue when the following GNU extensions are used:
|
|
|
|
|
|
* A array initializer without ``++=++``, which has been obsolete since GCC 2.5
|
|
* A structure member initializer with a colon, which has been obsolete since GCC 2.5.
|
|
* Case ranges
|
|
* Ternary operator with omitted second operand
|
|
|
|
|
|
== Noncompliant Code Example
|
|
|
|
----
|
|
struct S {
|
|
int f;
|
|
};
|
|
|
|
struct S s[] = {
|
|
[0] { // Noncompliant
|
|
f : 0 // Noncompliant
|
|
}
|
|
};
|
|
|
|
int fun(int p) {
|
|
switch (p) {
|
|
case 0 ... 1: // Noncompliant
|
|
do_the_thing();
|
|
break;
|
|
case 2:
|
|
//...
|
|
}
|
|
|
|
return p ?: 0; // Noncompliant
|
|
}
|
|
----
|
|
|
|
|
|
== Compliant Solution
|
|
|
|
----
|
|
struct S {
|
|
int f;
|
|
};
|
|
|
|
struct S s[] = {
|
|
[0] = {
|
|
.f = 0
|
|
}
|
|
};
|
|
|
|
int fun(int p) {
|
|
switch (p) {
|
|
case 0:
|
|
case 1:
|
|
do_the_thing();
|
|
break;
|
|
case 2:
|
|
//...
|
|
}
|
|
|
|
return p ? p: 0;
|
|
}
|
|
----
|
|
|