-2

I'm looking at C-based Solana Smart Contracts and I see -> operator in the code. How do I search for this as I don't even know what to call it (I have tried with no results)?

/**
 * @brief C-based Helloworld BPF program
 */
#include <solana_sdk.h>

uint64_t helloworld(SolParameters *params) {

  if (params->ka_num < 1) {
    sol_log("Greeted account not included in the instruction");
    return ERROR_NOT_ENOUGH_ACCOUNT_KEYS;
  }

  // Get the account to say hello to
  SolAccountInfo *greeted_account = &params->ka[0];

}

Frank C.
  • 7,758
  • 4
  • 35
  • 45
Shion
  • 319
  • 4
  • 12

2 Answers2

3

the -> operator is related to the . operator.

The . operator expects a variable with struct or union type on the left and the name of a member of that struct or union on the right.

The -> does the same thing, except that the left operand is a pointer to a struct or union.

That means that this:

params->ka_num

Is an equivalent and cleaner way of writing this:

(*params).ka_num 
dbush
  • 205,898
  • 23
  • 218
  • 273
1

It must be a pointer dereference operator ->.

Ivan Silkin
  • 381
  • 1
  • 7
  • 15