Skip to content

cgen: fix printing fn call of returning c struct value (fix #23104) - #23106

Merged
spytheman merged 5 commits into
vlang:masterfrom
yuyi98:fix_print_c_struct
Dec 9, 2024
Merged

spytheman merged 5 commits into
vlang:masterfrom
yuyi98:fix_print_c_struct

Conversation

@yuyi98

@yuyi98 yuyi98 commented Dec 9, 2024 •

Copy link
Copy Markdown
Member

This PR fix printing fn call of returning c struct value (fix #23104).

  • Fix printing fn call of returning c struct value.
  • Add test.

csize.h

struct Size {
   int width;
	int height;
};
#include "@VMODROOT/csize.h"

struct C.Size {
	width  int
	height int
}

type Size = C.Size

fn get_size() C.Size {
	return C.Size{11, 22}
}

fn get_csize() Size {
	return Size(C.Size{11, 22})
}

fn main() {
	println(get_size())
	assert true
	println(get_csize())
	assert true
}

Huly®: V_0.6-21543

@spytheman spytheman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

Comment thread vlib/v/tests/c_structs/return_csize_test.v
@spytheman
spytheman merged commit db49874 into vlang:master Dec 9, 2024
@yuyi98
yuyi98 deleted the fix_print_c_struct branch December 10, 2024 01:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

C error when printing C struct in V.

2 participants