1

I am looking for the source and/or proper definition for the int() function. I have searched through the source in Arduino.app, without much success.

The reference gives a terse explanation

int(x)
 x: a value of any type 
 Converts a value to the int data type

Passing 1, '1' or 49 returns the int 1. I haven't tested other types.

This seems to be an Arduino specific function - it doesn't seem to be in any c/c++ library.

2

int(x) is not a function but another way to perform an explicit cast of x to an int. It is part of the C++ language itself, that is why you could not find it in a library.

This is not Arduino-specific.

In C and C++ you can cast a value to an int by doing this:

int y = (int) x;

C++ has extended this notation by allowing to do it this way, which is equivalent:

int y = int(x);

You can find this in more details in C++ language reference.

  • to clear things i think add long x; above int y = int(x); in my opinion this would be better? – Martynas Jan 30 '15 at 6:35
  • Thanks. I could not find this in any of my (admittedly old) c++ books, or in Xcode documentation. – Milliways Jan 30 '15 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.