Generalized Lvalues - Red Hat ENTERPRISE LINUX 3 - USING GCC Using Instructions

Using the gnu compiler collection (gcc)
Hide thumbs Also See for ENTERPRISE LINUX 3 - USING GCC:
Table of Contents

Advertisement

Chapter 6. Extensions to the C Language Family
127
Compatibility Note: In addition to
, GCC 2 supported a more limited extension which permit-
typeof
ted one to write
typedef
=
;
T
expr
with the effect of declaring
to have the type of the expression
. This extension does not work
T
expr
with GCC 3 (versions between 3.0 and 3.2 will crash; 3.2.1 and later give an error). Code which relies
on it should be rewritten to use
:
typeof
typedef typeof(
)
;
expr
T
This will work with all versions of GCC.

6.7. Generalized Lvalues

Compound expressions, conditional expressions and casts are allowed as lvalues provided their
operands are lvalues. This means that you can take their addresses or store values into them.
Standard C++ allows compound expressions and conditional expressions as lvalues, and permits casts
to reference type, so use of this extension is deprecated for C++ code.
For example, a compound expression can be assigned, provided the last expression in the sequence is
an lvalue. These two expressions are equivalent:
(a, b) += 5
a, (b += 5)
Similarly, the address of the compound expression can be taken. These two expressions are equivalent:
&(a, b)
a, &b
A conditional expression is a valid lvalue if its type is not void and the true and false branches are
both valid lvalues. For example, these two expressions are equivalent:
(a ? b : c) = 5
(a ? b = 5 : (c = 5))
A cast is a valid lvalue if its operand is an lvalue. A simple assignment whose left-hand side is a cast
works by converting the right-hand side first to the specified type, then to the type of the inner left-
hand side expression. After this is stored, the value is converted back to the specified type to become
the value of the assignment. Thus, if
has type
, the following two expressions are equivalent:
a
char *
(int)a = 5
(int)(a = (char *)(int)5)
An assignment-with-arithmetic operation such as
applied to a cast performs the arithmetic using
+=
the type resulting from the cast, and then continues as in the previous case. Therefore, these two
expressions are equivalent:
(int)a += 5
(int)(a = (char *)(int) ((int)a + 5))
You cannot take the address of an lvalue cast, because the use of its address would not work out
coherently. Suppose that
were permitted, where
has type
. Then the following
&(int)f
f
float
statement would try to store an integer bit-pattern where a floating point number belongs:
*&(int)f = 1;

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ENTERPRISE LINUX 3 - USING GCC and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Enterprise linux 3

Table of Contents