A pointer to a constant
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
A pointer to a constant
It would be great if one could get a pointer to a constant what is required for some API functions.
Re: A pointer to a constant
A pointer to constant makes no sens, which API needs that ?
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: A pointer to a constant
Code: Select all
#ClassName = "MyWin"
wc.WNDCLASSEX
wc\cbsize = SizeOf(WNDCLASSEX)
wc\hInstance = hInstance
wc\lpfnWndProc = 0
wc\hCursor = LoadCursor_(0, #IDC_ARROW)
wc\hbrBackground = #COLOR_WINDOW
wc\lpszClassName = #ClassName ; It requires a pointer!
RegisterClassEx_(@wc)
hWnd = CreateWindowEx_(0, #ClassName, #ClassName, #WS_VISIBLE, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, #CW_USEDEFAULT, 0, 0, 0, 0)
Re: A pointer to a constant
The structure require a pointer to a string, but not to a constant!
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
http://msdn.microsoft.com/en-us/library ... 85%29.aspx
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: A pointer to a constant
I remember stumbling on this once or twice:
I had problems passing pointers to literal constants: @3.14 or @"mystring".
Instead, I created a variable and assigned it to my constant and then passed a pointer to my variable.
I had problems passing pointers to literal constants: @3.14 or @"mystring".
Instead, I created a variable and assigned it to my constant and then passed a pointer to my variable.
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: A pointer to a constant
In the constant string is stored. Right?
When the executable file is loaded into memory, all the constants be kept in memory, and why not get a pointer to this memory?
When the executable file is loaded into memory, all the constants be kept in memory, and why not get a pointer to this memory?
Re: A pointer to a constant
No constant in memory, all use of constants replaced with value. Constants not available in executable!User_Russian wrote:When the executable file is loaded into memory, all the constants be kept in memory, and why not get a pointer to this memory?
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: A pointer to a constant
What you are refering is a C macro, not a constant (there is no real constant in C).
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: A pointer to a constant
ts-soft, constant is loaded into memory, otherwise DataSection not exist.
A pointer to a constant can be obtained.
Otherwise, as you explained to this code works?And it is really a pointer to a constant and its value can be changed.
A pointer to a constant can be obtained.
Otherwise, as you explained to this code works?
Code: Select all
#Const = "Test"
*Point=0
!MOV dword [p_Point],_S1
Debug *Point
Debug PeekS(*Point)
x.s=#Const
Code: Select all
#Const = "Test"
*Point=0
!MOV dword [p_Point],_S2
Debug *Point
Debug PeekS(*Point)
PokeS(*Point, "1234")
x.s=#Const
Debug x
Re: A pointer to a constant
It's not true for numeric constants for example
-
- Addict
- Posts: 1518
- Joined: Wed Nov 12, 2008 5:01 pm
- Location: Russia
Re: A pointer to a constant
I mean the only string constants.
Re: A pointer to a constant
A literal string or constant string is in datasection. The constant in executable is replaced by pointer to the string, but the constant itself is no more available!
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.

Re: A pointer to a constant
Receiving a pointer to a string constant does make sense.
However, Fred's points are valid too.
I could imagine that PB combines constants (literal or #const) with the same value
into one single entry in the data section of the executable, so receiving a pointer
to that location makes perfect sense and is a valid reason for a feature request.
However, Fred's points are valid too.
I could imagine that PB combines constants (literal or #const) with the same value
into one single entry in the data section of the executable, so receiving a pointer
to that location makes perfect sense and is a valid reason for a feature request.
Blog: Why Does It Suck? (http://whydoesitsuck.com/)
"You can disagree with me as much as you want, but during this talk, by definition, anybody who disagrees is stupid and ugly."
- Linus Torvalds
Re: A pointer to a constant
Macro can't find the string pointer address

Code: Select all
#someconst$ = "Hello to you!"
Macro StrCmp(str1, str2, UseCase=#PB_String_NoCase)
Bool(CompareMemoryString(@str1, @str2, UseCase) = #PB_String_Equal) ;<-- Syntax Error in Macro @#Somestring$
EndMacro
s2$ = "hello World!"
Debug StrCmp(#SomeConst$,s2$) ; ,#PB_String_CaseSensitive)
The nice thing about standards is there are so many to choose from. ~ Andrew Tanenbaum