[Solved]Not understanding ::pinMode

Hello all

I downloaded GitHub - n0mjs710/MCP23S17: Arduino Driver for Microchip MCP23S17 to get started with the 23S17.

Below the begin method that uses ::pinMode(). As far as I can see, this is the normal Arduino pinMode function. Question is why there are two colons in front of it? Is it to differentiate from the pinMode function that is in this class? Any light ( :wink: ) reading that I can do somewhere?

void MCP::begin() {
  ::pinMode(_ss, OUTPUT);               // Set SlaveSelect pin as an output
  ::digitalWrite(_ss, HIGH);            // Set SlaveSelect HIGH (chip de-selected)
  SPI.begin();                          // Start up the SPI bus
  //SPI.setClockDivider(CLOCK_DIVIDER); // Sets the SPI bus speed
  //SPI.setBitOrder(MSBFIRST);          // Sets SPI bus bit order (this is the default, setting it for good form!)
  //SPI.setDataMode(SPI_MODE0);         // Sets the SPI bus timing mode (this is the default, setting it for good form!)
  byteWrite(IOCON, ADDR_ENABLE);
}

The double colon is the scope resolution operator. If there is no namespace in front of it, it refers to the global scope/namespace.

Since the MCP class also introduces its own scope with its own pinMode function, you have to specify explicitly that you want the function at the global scope, not MCP::pinMode, which would be the default inside of the MCP class.

Pieter

1 Like

Thanks Pieter for the explanation; it's as I suspected.

scope resolution operator is probably what I was looking for. I will try to find some light reading.