'dword ptr [K2]' is not a valid base/index expression

General discussion for topics related to the FreeBASIC project or its community.
Post Reply
badidea
Posts: 2586
Joined: May 24, 2007 22:10
Location: The Netherlands

'dword ptr [K2]' is not a valid base/index expression

Post by badidea »

This 'complex' code:

Code: Select all

Dim Shared k2 As integer
print k2
Triggers this error with 32-bit fbc (1.05.0 and 1.07.0) linux

Code: Select all

hello.asm:47: Error: `dword ptr [K2]' is not a valid base/index expression
(see also: https://freebasic.net/forum/viewtopic.p ... 88#p264088)

Is this a known bug?
coderJeff
Site Admin
Posts: 4313
Joined: Nov 04, 2005 14:23
Location: Ontario, Canada
Contact:

Re: 'dword ptr [K2]' is not a valid base/index expression

Post by coderJeff »

A known bug related to #515 Reserved variable names (0.21.1)

Short answer: the variable name given in fbc source code conflicts with predefined name in the assembler, and so can get weird assembly errors.

Aside from renaming the variable, a quick solution is to use a namespace:

Code: Select all

namespace mystuff
	dim shared K2 as integer
end namespace

using mystuff

K2 = 1234
print K2

dim i as integer
asm
	mov eax, [K2]
	mov [i], eax
end asm
print i
The decorated name in assembly is very different, i.e. in this case _ZN7MYSTUFF2K2E
yevrowl
Posts: 13
Joined: Aug 12, 2022 21:37
Location: Kiev
Contact:

Re: 'dword ptr [K2]' is not a valid base/index expression

Post by yevrowl »

This instruction helped with an error: "error: dword ptr is not a valid base/index expression".

Thanks a lot!
Post Reply