Home > Mobile >  How C alias works? [duplicate]
How C alias works? [duplicate]

Time:10-07

How does alias internally work in C ?
Does it allocate its own memory like pointers?
Otherwise how does the compiler treat it?
Is it like C Macro preprocessor computing?

int x=5;
int &y=x; //Assembly of this???

CodePudding user response:

Those are called references.

The standard doesn't describe how they (or anything else) work on the assembly level.

In practice, they are implemented as pointers, unless the compiler optimizes them away (which is easier for references compared to pointers, because they can't be reassigned).

They are unrelated to macros, the preprocessor doesn't know about references.

The standard contains some interesting wording for references: they "are not objects", the consequence being that you can't legally meaningfully examine their memory layout and modify it. But this is mostly a peculiarity of the wording; for most purposes they work like immutable pointers.

  • Related