inout

Using inouts with wand

£可爱£侵袭症+ 提交于 2019-12-12 03:27:27
问题 Consider the below code. module TriState ( // Outputs O, // Inouts IO, // Inputs OE, I ); parameter width = 1; input OE; input [width-1:0] I; output [width-1:0] O; inout [width-1:0] IO; assign IO = (OE) ? I : { width { 1'b1 } }; assign O = IO; endmodule // TriState module m1(.a(inout line_P1$IO)); reg val_P1 ; wire line_P1$IO,line_P1$O; TriState #(.width(32'd1)) line_SCL(.I(val_P1), .OE(1), .O(line_P1$O), .IO(line_P1$IO)); always @(*) begin val_P1 <= 1; end endmodule //m1 module m2(.a(inout

Declaring inout/input port as wand

旧城冷巷雨未停 提交于 2019-12-11 16:08:03
问题 When I execute the following code I get the then following error, but to my understanding input ports can be of net type, then why does this error occur? module a(inout<or input> i); wand i; endmodule Assertion failed: (0), function draw_net_input_x, file draw_net_input.c, line 727. sh: line 1: 25015 Done /opt/local/lib/ivl/ivlpp -L -F"/tmp/ivrlg2190eb213" -f"/tmp/ivrlg190eb213" -p"/tmp/ivrli190eb213" 25016 Abort trap: 6 | /opt/local/lib/ivl/ivl -C"/tmp/ivrlh190eb213" -C"/opt/local/lib/ivl

Are implicitly unwrapped optionals truly optionals?

此生再无相见时 提交于 2019-12-10 20:59:45
问题 In Swift 4.0, the following code doesn't compile: var str: String! func someFunc(_ s: inout String?) {} someFunc(&str) Now I imagine that str is of type String? in actuality, and the Swift compiler seems to agree: Cannot pass immutable value of type 'String?' as inout argument I can fix this by either changing the the variable to type String? or the function parameters to (_ s: inout String!) but I don't understand why I have to. Swift already seems to agree that var str : String! is "of type

Immutable value as inout argument

試著忘記壹切 提交于 2019-12-07 00:18:43
问题 I would like to have a pointer as a parameter of a class. But when I am trying to code the init, I am having this error: Cannot pass immutable value of type 'AnyObject?' as inout argument class MyClass { var valuePointer: UnsafeMutablePointer<AnyObject?> init(value: inout AnyObject?) { self.valuePointer = &value } } I would like to create some instance of MyClass which can all refer to the same "value". Then, when I am editing this value in this class, it would change everywhere else. This is

Immutable value as inout argument

 ̄綄美尐妖づ 提交于 2019-12-05 04:02:18
I would like to have a pointer as a parameter of a class. But when I am trying to code the init, I am having this error: Cannot pass immutable value of type 'AnyObject?' as inout argument class MyClass { var valuePointer: UnsafeMutablePointer<AnyObject?> init(value: inout AnyObject?) { self.valuePointer = &value } } I would like to create some instance of MyClass which can all refer to the same "value". Then, when I am editing this value in this class, it would change everywhere else. This is the first time I'm working with pointer in Swift. I guess I am doing it wrong... For those who has the

How to update a value in a nested dictionary given path fragment in Swift?

余生长醉 提交于 2019-12-02 00:51:13
I have a nested dictionary and an array containing path fragment. I need to update the value at that location. I am possibly looking for a recursive function instead of extensions to Dictionary types and such. I am not able to do this recursively because I making a copy of the inout param. var dict: [String: Any] = ["channel": ["item": ["title": 1111]]] var pathFrag = ["channel", "item", "title"] var val = 123 func addAt(pathFrag: inout [String], val: Int, data: inout [String: Any]) { if let first = pathFrag.first { if let item = data[first] { print(item) pathFrag.remove(at: 0) if !pathFrag

Using inout keyword: is the parameter passed-by-reference or by copy-in copy-out (/call by value result)

我们两清 提交于 2019-12-01 19:04:52
Question: Based on the information and discussion below: Are inout parameters passed-by-reference or by copy-in copy-out ? Based on the following SO threads, function parameters marked by the inout keyword is passed by reference : Does inout/var parameter make any difference with reference type? Is Swift Pass By Value or Pass By Reference Why doesn't inout pass by reference? We note that the two top-most threads are pre-Swift 2.0; I haven't been able to find any newer discussion on the subject here on SO (except the somewhat related third thread link). Based on Apple's documentation (as far as

Why can't I pass an implicitly unwrapped optional as an UnsafeMutablePointer?

本秂侑毒 提交于 2019-12-01 10:30:13
It seems that Xcode 9.3 does fix one issue I was having , but in Swift 4.1 the second half of this code still doesn't compile: var obj: SomeClass! ; class SomeClass {} func inoutFunc(_: inout SomeClass?) {} inoutFunc(&obj) // works func pointerFunc(_: UnsafeMutablePointer<SomeClass?>) {} pointerFunc(&obj) // <-- COMPILER ERROR The call to inoutFunc is now fine, but the call to pointerFunc still gives me an error: Cannot invoke 'pointerFunc' with an argument list of type '(inout SomeClass!)' Or in the original context: Cannot pass immutable value of type 'ActualClass?' as inout argument Similar

Why can't I pass an implicitly unwrapped optional as an UnsafeMutablePointer?

孤者浪人 提交于 2019-12-01 07:41:25
问题 It seems that Xcode 9.3 does fix one issue I was having, but in Swift 4.1 the second half of this code still doesn't compile: var obj: SomeClass! ; class SomeClass {} func inoutFunc(_: inout SomeClass?) {} inoutFunc(&obj) // works func pointerFunc(_: UnsafeMutablePointer<SomeClass?>) {} pointerFunc(&obj) // <-- COMPILER ERROR The call to inoutFunc is now fine, but the call to pointerFunc still gives me an error: Cannot invoke 'pointerFunc' with an argument list of type '(inout SomeClass!)' Or

What does an ampersand (&) mean in the Swift language?

回眸只為那壹抹淺笑 提交于 2019-11-27 06:57:47
I know about the ampersand as a bit operation but sometimes I see it in front of variable names. What does putting an & in front of variables do? Icaro It works as an inout to make the variable an in-out parameter. In-out means in fact passing value by reference, not by value. And it requires not only to accept value by reference, by also to pass it by reference, so pass it with & - foo(&myVar) instead of just foo(myVar) As you see you can use that in error handing in Swift where you have to create an error reference and pass it to the function using & the function will populate the error