Home | History | Annotate | Line # | Download | only in indent
lsym_unary_op.c revision 1.6
      1 /* $NetBSD: lsym_unary_op.c,v 1.6 2023/05/13 06:52:48 rillig Exp $ */
      2 
      3 /*
      4  * Tests for the token lsym_unary_op, which represents a unary operator.
      5  *
      6  * In an expression, a unary operator is written without blank next to its
      7  * argument.
      8  *
      9  * In a type name, the "unary operator" '*' represents the derivation of a
     10  * pointer type.
     11  *
     12  * See also:
     13  *	lsym_binary_op.c
     14  *	lsym_postfix_op.c
     15  *	C11 6.4.6 "Punctuators"
     16  *	C11 6.5 "Expressions"
     17  */
     18 
     19 //indent input
     20 void
     21 unary_operators(void)
     22 {
     23 	/* In the order of appearance in C11 6.5. */
     24 	function(a++, a--, ++a, --a, &a, *a, +a, -a, ~a, !a);
     25 }
     26 //indent end
     27 
     28 //indent run-equals-input
     29 
     30 
     31 /*
     32  * The unary operators '+' and '-' can occur in long chains.  In these chains,
     33  * adjacent '+' must not be merged to '++' since that would be a different
     34  * token.  The same applies to '&', but that case is irrelevant in practice
     35  * since the address of an address cannot be taken.
     36  */
     37 //indent input
     38 int var=+3;
     39 int mixed=+-+-+-+-+-+-+-+-+-+-+-+-+-3;
     40 int count=~-~-~-~-~-~-~-~-~-~-~-~-~-3;
     41 int same = + + + + + - - - - - 3;
     42 //indent end
     43 
     44 //indent run -di0
     45 int var = +3;
     46 int mixed = +-+-+-+-+-+-+-+-+-+-+-+-+-3;
     47 int count = ~-~-~-~-~-~-~-~-~-~-~-~-~-3;
     48 int same = + + + + +- - - - -3;
     49 //indent end
     50 
     51 
     52 /*
     53  * A special kind of unary operator is '->', which additionally suppresses the
     54  * next space.
     55  */
     56 //indent input
     57 int var = p -> member;
     58 //indent end
     59 
     60 //indent run -di0
     61 int var = p->member;
     62 //indent end
     63 
     64 
     65 //indent input
     66 void
     67 unary_operators(void)
     68 {
     69 	++prefix_increment;
     70 	--prefix_decrement;
     71 	int *address = &lvalue;
     72 	int dereferenced = *address;
     73 	int positive = +number;
     74 	int negative = -number;
     75 	bool negated = !condition;
     76 }
     77 //indent end
     78 
     79 //indent run-equals-input -di0
     80