Pergunta

I know that if I'm looking for the source code of a specific function like printf I can see it when I download the glibc and simply open that file.

But where is the source code or definition of the standard data types like int, or double, etc...

Thanks I'm curious!

Ok, I am not looking for what a function or variable or a data type actually is. I want that file which contains the definition of "int". Is it a structure? But it might be defined somewhere in the GCC... just cant find the file

Foi útil?

Solução 2

Only complex data types can be defined as structures, primitive data types are just conventions of how to lay out bits in memory. The details of those conventions are defined differently in each compiler, across dozens of files handling the different machine code implementations of operations defined on those primitive types.

Indeed there will likely be hundreds of files within gcc in which parts of the implementation of an int is defined: each operation (cast to char/uint/double/float/etc, plus, times, subtract, divide etc) on each of the dozens of architectures (x86, x86-64, PowerPC) will need to have code generation, optimisations, widths and more defined.

I'd recommend getting a basic understanding of how a compiler works (the standard passes: tokenize, parse, analyse, IL generation, optimisation, code generation) the class I took on it used The Dragon Book but I've heard others say it's a little dated.

Outras dicas

Primitive variables like int, and double don't actually have a 'source code' per se.

Their implementation isn't even very strictly defined by the standard. The hardware that the program runs directly implements the functionality of them, and thus it is the hardware that defines what an int is.

However, if you are curious about how they are implemented, most computers use a twos-complement system for signed integers; and, the IEEE Floating point standard for implementing doubles and floats.

But none, of this is guaranteed by the C language.

From a computers' point of view int and double are a few bytes in memory representing numbers ,while printf is a function which can be called and executed. Read this: http://en.wikipedia.org/wiki/Primitive_data_type

int and double are datatypes,while printf is a function

You cant get source code of data types,they are defined as the data storage format that a variable can store a data to perform a specific operation.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top