What is the "VALUE" type in Ruby source files?

I'm new to Ruby, but when I was looking for Ruby documentation, I also found the C source code that was included in the documentation. In almost all of these links, I found VALUE , and I'm sure this is a struct . But what are the attributes of this VALUE struct and what does it actually do?

+6
source share
2 answers

You can see the VALUE definition in the ruby/ruby.h header file:

 #if defined HAVE_UINTPTR_T && 0 typedef uintptr_t VALUE; ... #elif SIZEOF_LONG == SIZEOF_VOIDP typedef unsigned long VALUE; ... #else # error #endif 

So this is just a pointer to an object. As described in the Priti link, there is a TYPE() macro in the same file that can be used to identify the type of data that VALUE points to.

+9
source

In C, variables are types and data is not types. In contrast, Ruby variables do not have a static type, and the data itself has types, so the data must be converted between languages.

The data in Ruby is represented by the C-type "VALUE". Each VALUE value has a data type.

To get C data from VALUE, you need to:

1. Define the data type VALUE

2. Convert VALUE to C data

For more information, see here: Basic Knowledge

+3
source

Source: https://habr.com/ru/post/944448/


All Articles