After browsing the forums a bit I've stumbled across a discussion about C-style "volatile" and lack of something like that in D (I did not get too deep in the details yet), so I'd like to ask if there is something that can be used for the purpose of forcing memory accesses to happen ALWAYS, disregarding what sense such operations make to the compiler/optimizer?

In MCUs it's for example common for one peripheral register (memory address) to perform two distinct functions, depending on whether you read or write:

SPI->DR = data_to_send[0];
SPI->DR = data_to_send[1];
SPI->DR = data_to_send[2];
data_received[0] = SPI->DR;
data_received[1] = SPI->DR;
data_received[2] = SPI->DR;

This cannot be mixed, this cannot be skipped, this cannot be concatenated, as each read/write has to take place exactly in the order specified.

In C this is handled by making the memory address pointed "volatile":

typedef struct SPI_s
{
volatile uint32_t DR;
volatile uint32_t REG1;
volatile uint32_t REG2;
} SPI_t;

#define SPI ((SPI_t*)0x12345678)

How would you handle things like that in D? Is that possible? That's a crucial thing for system-programming (;

4\/3!!

Reply via email to