-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: allow compound literals with address-of operator
- Loading branch information
1 parent
adcc29c
commit f106b9b
Showing
3 changed files
with
37 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
struct s { | ||
int i; | ||
}; | ||
|
||
void struct_with_exp(const unsigned int buffer_size, int buffer[const]){ | ||
if (buffer_size < 1) return; | ||
|
||
struct s *p; | ||
int j = 42; | ||
p = &((struct s){j++}); // Compound literal with address-of operator and post-increment operator | ||
|
||
buffer[0] = p->i; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use crate::struct_with_exp::rust_struct_with_exp; | ||
use libc::{c_int, c_uint, size_t}; | ||
|
||
#[link(name = "test")] | ||
extern "C" { | ||
fn struct_with_exp(_: c_uint, _: *mut c_int); | ||
} | ||
|
||
const BUFFER_SIZE: usize = 1; | ||
|
||
pub fn test_struct_with_exp() { | ||
let mut buffer = [0; BUFFER_SIZE]; | ||
let mut rust_buffer = [0; BUFFER_SIZE]; | ||
let expected_buffer = [42]; | ||
|
||
unsafe { | ||
struct_with_exp(BUFFER_SIZE as u32, buffer.as_mut_ptr()); | ||
rust_struct_with_exp(BUFFER_SIZE as u32, rust_buffer.as_mut_ptr()); | ||
} | ||
|
||
assert_eq!(buffer, rust_buffer); | ||
assert_eq!(buffer, expected_buffer); | ||
} |