const int* p;
int const* p;
is afaik the same and its messed
imo those wordls should adhere to things right to them so
logically
*int p //pointer to int p
const* int p //coinst pointer to int
const* const int p// const pointer to const int
const char* const int x //constt char-size pointer to const int
long const* const int x //long size const pointer to const int
fir pisze:
const int* p;
int const* p;
is afaik the same and its messed
imo those wordls should adhere to things right to them so
logically
*int p //pointer to int p
const* int p //coinst pointer to int
const* const int p// const pointer to const int
const char* const int x //constt char-size pointer to const int
long const* const int x //long size const pointer to const int
note for moral uses it would be
*int //pointer/reference to int LETS SAY name a constant pointers a references maybe for sipmplicity, this here if its pointer or reference depends if it is by defaulf const or not so if it is by default
reference or pointer)
const* int // reference to int
*const int //pointer or reference to read int
const*const int //reference to read int
(as i said thos word const ale flaw but for illustration)
im not sure if pointer or reference should be default, also some may use
two signs
*int p //pointer
&int p // reference (const pointer)
THIUGH probably maybe its better tu use one
in separate theread i noticed that references are same as pointers but
with swapped syntax and changed symbol
NORMAL
int*x;
x //pointer value
*x //value
SWAPPED SYNTAX: (fictional)
int* x;
*x //pointer value
x ; //value
i talk about this reversed syntax becouse this
syntax has more sense becouse you more often acces value than
use pointer value
REFERENCE:
int& x;
&x; //pointer value (kinda)(there is subtle difference as in reversed pointer syntax you would be able to change it)
x; //value
SO IN SHORT
if you swap syntax of pointers on more sane where xis value and *x is
aeress (not like today *x is value and x is adress) you will get the c++ reference except that in c++ afaik (i not used it really in my life as
i distaste c++) you cannot change it
On 20/05/2026 04:13, fir wrote:
in separate theread i noticed that references are same as pointers but
with swapped syntax and changed symbol
NORMAL
int*x;
x //pointer value
*x //value
SWAPPED SYNTAX: (fictional)
int* x;
*x //pointer value
x ; //value
i talk about this reversed syntax becouse this
syntax has more sense becouse you more often acces value than
use pointer value
REFERENCE:
int& x;
&x; //pointer value (kinda)(there is subtle difference as in
reversed pointer syntax you would be able to change it)
x; //value
SO IN SHORT
if you swap syntax of pointers on more sane where xis value and *x is
aeress (not like today *x is value and x is adress) you will get the
c++ reference except that in c++ afaik (i not used it really in my
life as
i distaste c++) you cannot change it
This is where a HLL varies from Assembly; take this variable A (in C,
'int A;'):
A: dd 0
mov rax, A # A by itself is its address
mov eax, [A] # Use [A] to dereference get its value
If that was the same in a HLL, then you'd write this:
int a, b, c;
a; // address of a (&a now)
*a; // value of a
*a = *b + *c;
That would be inconvenient however, so most HLLs will automatically dereference variables names so that you get the value. You need &a to
get their address (some languages can figure out what you're trying to do).
Bart pisze:
On 20/05/2026 04:13, fir wrote:you mean this *a is to remember this dereference like
in separate theread i noticed that references are same as pointers
but with swapped syntax and changed symbol
NORMAL
int*x;
x //pointer value
*x //value
SWAPPED SYNTAX: (fictional)
int* x;
*x //pointer value
x ; //value
i talk about this reversed syntax becouse this
syntax has more sense becouse you more often acces value than
use pointer value
REFERENCE:
int& x;
&x; //pointer value (kinda)(there is subtle difference as in
reversed pointer syntax you would be able to change it)
x; //value
SO IN SHORT
if you swap syntax of pointers on more sane where xis value and *x is
aeress (not like today *x is value and x is adress) you will get the
c++ reference except that in c++ afaik (i not used it really in my
life as
i distaste c++) you cannot change it
This is where a HLL varies from Assembly; take this variable A (in C,
'int A;'):
A: dd 0
mov rax, A # A by itself is its address
mov eax, [A] # Use [A] to dereference get its value >>
If that was the same in a HLL, then you'd write this:
int a, b, c;
a; // address of a (&a now)
*a; // value of a
*a = *b + *c;
That would be inconvenient however, so most HLLs will automatically
dereference variables names so that you get the value. You need &a to
get their address (some languages can figure out what you're trying to
do).
[0x9879879] -> 0x33373873
its kinda nonsense in practice imo as it you use few *a *a *a *a
but you not change a in a row the first time only compiler dereferences [0x9879879] then it uses 0x33373873 if it is sane compiler not
[0x9879879] every time so this *a is not illustrating but is misleading
in fact if a is reference to rint not to int (rint i mean this typedef
conts int rint;) then when you writa a it could in fact not to use 0x33373873 but immediate value, say 3
so here are 3 levels
int* - [0x09879879]
int/int& - 0x33373873
rint/rint& - 3
it imo says you should use int/int& instead of int* when appropriate and rint/rint& instead of int/int& when appropriate
(though it would need to be tested in practice
i only now concluded that int& are better and rints are better, never
used it massively
fir pisze:
Bart pisze:note this damn flow in function arguments
On 20/05/2026 04:13, fir wrote:you mean this *a is to remember this dereference like
in separate theread i noticed that references are same as pointers
but with swapped syntax and changed symbol
NORMAL
int*x;
x //pointer value
*x //value
SWAPPED SYNTAX: (fictional)
int* x;
*x //pointer value
x ; //value
i talk about this reversed syntax becouse this
syntax has more sense becouse you more often acces value than
use pointer value
REFERENCE:
int& x;
&x; //pointer value (kinda)(there is subtle difference as in >>>> reversed pointer syntax you would be able to change it)
x; //value
SO IN SHORT
if you swap syntax of pointers on more sane where xis value and *x
is aeress (not like today *x is value and x is adress) you will get
the c++ reference except that in c++ afaik (i not used it really in >>>> my life as
i distaste c++) you cannot change it
This is where a HLL varies from Assembly; take this variable A (in C,
'int A;'):
A: dd 0
mov rax, A # A by itself is its address
mov eax, [A] # Use [A] to dereference get its value
If that was the same in a HLL, then you'd write this:
int a, b, c;
a; // address of a (&a now) >>> *a; // value of a
*a = *b + *c;
That would be inconvenient however, so most HLLs will automatically
dereference variables names so that you get the value. You need &a to
get their address (some languages can figure out what you're trying
to do).
[0x9879879] -> 0x33373873
its kinda nonsense in practice imo as it you use few *a *a *a *a
but you not change a in a row the first time only compiler dereferences
[0x9879879] then it uses 0x33373873 if it is sane compiler not
[0x9879879] every time so this *a is not illustrating but is misleading
in fact if a is reference to rint not to int (rint i mean this typedef
conts int rint;) then when you writa a it could in fact not to use
0x33373873 but immediate value, say 3
so here are 3 levels
int* - [0x09879879]
int/int& - 0x33373873
rint/rint& - 3
it imo says you should use int/int& instead of int* when appropriate and
rint/rint& instead of int/int& when appropriate
(though it would need to be tested in practice
i only now concluded that int& are better and rints are better, never
used it massively
foo(char* txt, unsigned color)
{
//...
}
//here it should be
foo(rchar* txt, runsigned color)
becouse in most cases youre interested in value of color not its
real adress..sometimes you may use the adrees of color like using it
like local variable (color=color&0xff00 etc) buts its kinda side
effect - normally youre interested in values not having local copies
so it shows most cases if not all argument should be const/read only
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,118 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 16:36:59 |
| Calls: | 14,340 |
| Calls today: | 3 |
| Files: | 186,356 |
| D/L today: |
2,558 files (803M bytes) |
| Messages: | 2,532,455 |