milan
milan

Reputation: 2219

what does the * mean in c

This is a C language question.

Does the * mean multiply or something else in function below? The reason I ask is because the function definition comments says it expects three params. Also do the () [parenthesis] in the #defines mean something different from no parenthesis? See below.

The function call:

nvm_eeprom_write_byte(TEST_ERASE_PAGE * EEPROM_PAGE_SIZE, 42);

The definitions:

#define TEST_ERASE_PAGE 2
#define EEPROM_PAGE_SIZE 32

Comments for the function definition:

The function definition:

void nvm_eeprom_write_byte(eeprom_addr_t address, uint8_t value) {}

eeprom_addr_t is a typedef:

typedef uint16_t eeprom_addr_t
#define EEPROM_START     (0x0000)
#define EEPROM_SIZE      (2048)
#define EEPROM_PAGE_SIZE (32)
#define EEPROM_END       (EEPROM_START + EEPROM_SIZE - 1)

Upvotes: 1

Views: 2253

Answers (2)

mpenkov
mpenkov

Reputation: 21922

Yes, * means multiply in C.

Parenthesis in #define is a standard practice in C to prevent unexpected results when using compound statements (where operator precedence matters).

Consider the difference between

#define FOO 1+2
int a = FOO*2

and

#define FOO (1+2)
int a = FOO*2

Upvotes: 2

Ben Zotto
Ben Zotto

Reputation: 71058

Yes, it just means multiply in this context. It's multiplying two #defined constant to make the first argument to the nvm_eeprom_write_byte function.

This code involves a lot of assumptions about memory address manipulation. Gotta be honest with you, if you don't know C, looking at EEPROM driver code probably isn't the simplest or safest way to start.

Upvotes: 5

Related Questions