r/cprogramming • u/GoingGranola • Aug 13 '26
uint16_t addr = 1 * EEPROM_CHUNK_SIZE
Is * used as a pointer in this occasion or multiplier?
EEPROM_CHUNK_SIZE is 1
0
Upvotes
r/cprogramming • u/GoingGranola • Aug 13 '26
Is * used as a pointer in this occasion or multiplier?
EEPROM_CHUNK_SIZE is 1
11
u/Delta_G_Robotics Aug 13 '26
The * is a multiply here.
7
u/glasket_ Aug 13 '26
It's multiplication.
*is a deref operator when there isn't a valid operand on the left, otherwise it's multiplication.1 *makes it multiplication, because otherwise it would be invalid syntax to have1 (*ptr).3
u/Maleficent_Memory831 Aug 13 '26
Binary operator in an experession means it's a multiply. A unary operator in an expression would be a pointer dereference.
Ie, "a + * b", will parse as "(a + (* b))". Some times it is worth putting in parantheses in the trickier cases so as to not confuse the readers.
In the case you cite, if you treated it as a pointer dereference then it would have been a syntax error, ie, "uint16_t addr = 1 (* constant)".
3
u/sciencekm Aug 13 '26
"1 * ???" is always a multiply.
1
u/fllthdcrb Aug 13 '26
Everything on the right-hand side of the
=is the initializer, which is an expression.*in an expression is an operator (either dereference when unary, or multiplication when binary), unless it appears in a type cast.1
u/SmokeMuch7356 Aug 14 '26
It has to be multiplication -
1 (*EEPROM_CHUNK_SIZE)would not be a valid expression.