Eos: Question regarding the meaning of N() syntax

Created on 19 Jan 2018  ·  3Comments  ·  Source: EOSIO/eos

I know this might be a dummy question, but it is troubling me a lot.
I am trying to follow the tutorial at https://github.com/EOSIO/eos/wiki/Tutorials#2-currency-contract-walkthrough, and in a lot of the places it has this syntax "N()", like:

typedef eosio::token<uint64_t,N(currency)> currency_tokens;

or in contracts/currency/currency.cpp:73

const uint64_t key = N(account);

I am coming from Java and Python, and knows a little about C++ and template, and it is kind of hard for me to understand what N(something) does here. Does it act as a generic constructor (like new Object() in Java), or it is something else?

Most helpful comment

For those landing here, looks like the link is now:
https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/types.hpp

See:

   /**
    * @brief used to generate a compile time uint64_t from the base32 encoded string interpretation of X
    * @ingroup types
    */
   #define N(X) ::eosio::string_to_name(#X)

All 3 comments

I think it is a #define. So expanded at pre-processor stage.

@asiniscalchi is right, it is a preprocessor macro that expands to ::eosio::string_to_name(#X) here.

If you are unfamiliar with preprocessor macros in C/C++ the # turns the argument into a string literal. For instance N(account) becomes ::eosio::string_to_name("account")

For those landing here, looks like the link is now:
https://github.com/EOSIO/eos/blob/master/contracts/eosiolib/types.hpp

See:

   /**
    * @brief used to generate a compile time uint64_t from the base32 encoded string interpretation of X
    * @ingroup types
    */
   #define N(X) ::eosio::string_to_name(#X)
Was this page helpful?
0 / 5 - 0 ratings

Related issues

congnghebitcoin picture congnghebitcoin  ·  3Comments

ResponsiveWebApps picture ResponsiveWebApps  ·  3Comments

sim31 picture sim31  ·  3Comments

bezalel picture bezalel  ·  3Comments

williamleecn picture williamleecn  ·  3Comments