Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C error printing the reference of a not integer variable. #23461

Open
jorgeluismireles opened this issue Jan 14, 2025 · 2 comments
Open

C error printing the reference of a not integer variable. #23461

jorgeluismireles opened this issue Jan 14, 2025 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Jan 14, 2025

Describe the bug

We have a variable other than int, we create a reference and tried to print the reference.

Reproduction Steps

fn main() {
	s := 'Hello'
	p := &s
	println('${p}')
}

If above s is int or u8 there is no error and prints a number. If s is rune or f32 also there is a C error.

Expected Behavior

Get the number of the address (like with an integer).

Current Behavior

Running code...
Can't run code. The server returned an error:
/tmp/v_60000/../../../../../../box/code.v:4: warning: implicit declaration of function 'isnil'
/home/admin/v/thirdparty/tcc/lib/libgc.a: error: 'GC_noop1_ptr' defined twice
tcc: error: undefined symbol 'isnil'
builder error: 
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
Exited with error status 1
Please try again.

Possible Solution

Related with this issue #23460

Additional Information/Context

In REPL is harmless:

____    ____ 
 \   \  /   /  |  Welcome to the V REPL (for help with V itself, type  exit , then run  v help ).
  \   \/   /   |  Note: the REPL is highly experimental. For best V experience, use a text editor, 
   \      /    |  save your code in a  main.v  file and execute:  v run main.v 
    \    /     |  V 0.4.9 6f7cbd1 . Use  list  to see the accumulated program so far.
     \__/      |  Use Ctrl-C or  exit  to exit, or  help  to see other available commands.

>>> s := 'Hello'
>>> p := &s
>>> println('${p}')
&Hello
>>> 

V version

V 0.4.9 a20fff9

Environment details (OS name and version, etc.)

https://play.vlang.io/p/04a4c8aab1

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

@jorgeluismireles jorgeluismireles added the Bug This tag is applied to issues which reports bugs. label Jan 14, 2025
Copy link

Connected to Huly®: V_0.6-21891

@jorgeluismireles
Copy link
Author

Commits linked here solved the C error problem by printing & followed by the value of the object referenced. I noticed printing the references with :x format we can get the numbers as with integers:

r, s, t, u, v := 1, 'Hello', `a`, 3.14, [1,2,3]
pr, ps, pt, pu, pv := &r, &s, &t, &u, &v
println('${pr} ${ps} ${pt} ${pu} ${pv}')
println('${pr:x} ${ps:x} ${pt:x} ${pu:x} ${pv:x}')

produces

1520ee921fe0 &Hello &a &3.14 &[1, 2, 3]
1520ee921fe0 1520ee922fe0 1520ee921fd0 1520ee921fc0 1520ee924fc0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

No branches or pull requests

1 participant