Two words, a space, and a terminator in C code. What does this accomplish?

I am having a hard time with what the third line is doing in this code exactly.

I spent over two hours in a C book and online trying to figure out what the line “RH_ASK driver;” is doing in terms of writing C/C++.

I am having a problem because “RH_ASK” does not appear to be a keyword and “driver” does not appear to be a keyword either. Then just a terminator.

Line three to me consists of two strings of characters, a space, and a terminator.

What is the name of what this action is in C code so I can research it?


#include <RH_ASK.h>
#include <SPI.h> // Not actually used but needed to compile

RH_ASK driver;

void setup()
    Serial.begin(9600);	  // Debugging only
    if (!driver.init())
         Serial.println("init failed");

void loop()
    const char *msg = "Hello World!";
    driver.send((uint8_t *)msg, strlen(msg));

It defines a variable of type RH_ASK that is named 'driver'. But, it is more than a simple variable. It is an instance of the class RH_ASK. You can get an idea of what it's capable of doing by looking in the file 'RH_ASK.h'

The first thing you need to understand is that, after some minimal preprocessing, the .ino files of Arduino sketches are compiled as C++, not C. Although there are many similarities between C and C++, there are also significant differences, which are used extensively in Arduino code. So I wouldn't recommend using C references to try to understand Arduino code, unless you are looking at code in a .c file. Instead, use a C++ reference.

More information:

You will find the linkage of these words: RH_ASK and driver with the following excerpt taken from RH_ASK.h file.

class RH_ASK 
    RH_ASK(uint16_t speed = 2000, uint8_t rxPin = 11, uint8_t txPin = 12, uint8_t pttPin = 10, bool pttInverted = false);
    virtual bool    init();
    virtual bool    available();
    virtual bool    recv(uint8_t* buf, uint8_t* len);
    virtual bool    send(const uint8_t* data, uint8_t len);
    virtual uint8_t maxMessageLength();  
    void           setModeIdle();
    void           setModeRx();
    void           setModeTx();
    void            handleTimerInterrupt();
    uint16_t        speed() { return _speed;}

    uint8_t         timerCalc(uint16_t speed, uint16_t max_ticks, uint16_t *nticks);
    void            timerSetup();
    bool            readRx();
    void            writeTx(bool value);
    void            writePtt(bool value);
    uint8_t         symbol_6to4(uint8_t symbol);
    void            receiveTimer();
    void            transmitTimer();
    void            validateRxBuf();
    uint16_t        _speed;
    uint8_t         _rxPin;
    uint8_t         _txPin;
    uint8_t         _pttPin;
    bool            _rxInverted;
    bool            _pttInverted;
    volatile bool   _rxBufFull;
    volatile bool   _rxBufValid;
    volatile bool   _rxLastSample;
    volatile uint8_t _rxIntegrator;
    volatile uint8_t _rxPllRamp;
    volatile uint8_t _rxActive;
    volatile uint16_t _rxBits;
    volatile uint8_t _rxBitCount;
    uint8_t _rxBuf[RH_ASK_MAX_PAYLOAD_LEN];
    volatile uint8_t _rxCount;
    volatile uint8_t _rxBufLen;
    uint8_t _txIndex;
    uint8_t _txBit;
    uint8_t _txBuf[(RH_ASK_MAX_PAYLOAD_LEN * 2) + RH_ASK_PREAMBLE_LEN];
    uint8_t _txBufLen;

1. The word class (with small c) is a keyword -- a concept of C++ and not C. We observe that there are many variables and functions with {} of the above declaration. This is the class keyword which ensures that who (which part of the sketch) can access which variables and which functions. This is a matter of data security. In order to acquire basic understanding on the role of class keyword, please practice small C++ examples from the net.

2. The next word RH_ASK is the familiar tag which, in C++, is known as Class (Capital C) Name or Class (Capital C). RH_ASK encompasses (refers to) all the data (the variables and functions) within {} of the above declaration. From C's point of view, RH_ASK could be seen/said a 'data type'.

3. Now, from the RH_ASK Class we can create an object (from C++'s perspective). So, we can have:

RH_ASK driver;

Here, driver is an object which holds 'both data and procedures (functions) for manipulating these data' which are of type RH_ASK, and we already know what RH_ASK encompasses.

In reality, the C++'s concepts are highly nested; therefore, users should remain concentrated on the correct use of methods on objects to carry out various operations on hardware.

If you are interested, I can post a Class based sketch to blink built-in LED (L) of Arduino UNO. This is to demonstrate the use of Class, Object, and Constructor in the hardware context of Arduino UNO.

The line

RH_ASK driver;

is structurally the same as

int myNumber;

The first part is the Type and the second part is the name that you decide to give the instance of that type


I would like to thank you all for the help.

You all knocked this one out of the park for me.

I will be focusing my attention to studying the concepts of classes and objects now.

Golam, thank you for offering to post the code but you all answered my question beautifully and I don't need.

Thanks again.

jdemar1: Golam, thank you for offering to post the code but you all answered my question beautifully and I don't need

Are you sure that you don't need the Class based sketch on Arduino hardware I wished to post?