In C, does an array 'access' without storing in a variable actually read from memory? -


i'm trying measure time takes memory accesses, , we're run loop , access elements char array. here code:

int i; clock_gettime(clock_monotonic, &start); for(i = 0; < size; i+=stride) {     array[i]; } clock_gettime(clock_monotonic, &stop); 

my question is: statement 'array[i]' without storing value in variable, e.g. char x = array[i], still make array access memory?

it depends on mean "memory access".

the language specification not have concept of "memory access". closest has offer concept of lvalue conversion described 6.3.2.1 of c11. process of converting lvalue non-lvalue language-level idea of reading data storage intermediate ethereal "holding area" further processing. language specification says lvalue conversion applied always, "except when operand of sizeof operator, unary & operator, ++ operator, -- operator, or left operand of . operator or assignment operator". not exclude example, meaning lvalue conversion applied result of array[i], i.e. purely conceptually data read memory.

of course, in real life no self-respecting compiler waste efforts on evaluating value of array[i] discard afterwards.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -