calling c functions in Objective C [duplicate] - ios

This question already has answers here:
Calling C from Objective C
(3 answers)
Closed 9 years ago.
Hi I am trying to use some pure C library in an iOS app, however I have no clue how to call and pass the parameters. Here are 2 functions, Node is a struct:
Node *parse(FILE *f);
void add_subnode(Node *t, Node *parent);
Can someone show me some sample code how to do it? Or point out to me some good books on this topic.
Thanks
Ray

You could call C functions like this:
Node *node = parse(f); // node will hold return value
add_subnode(t, parent);

Related

Get uint64_t out of __m128 intrinsic? [duplicate]

This question already has answers here:
C++ SSE Intrinsics: Storing results in variables [closed]
(1 answer)
print a __m128i variable
(4 answers)
SSE: Difference between _mm_load/store vs. using direct pointer access
(3 answers)
How to extract bytes from an SSE2 __m128i structure?
(1 answer)
Is `reinterpret_cast`ing between hardware SIMD vector pointer and the corresponding type an undefined behavior?
(2 answers)
Closed 1 year ago.
I can use _mm_set_epi64 to store two uint64_ts into a __m128 intrinsic. But hunting around, I see various ways to get the values back out: There's reinterpret_cast (and it's evil twin C-style casts), it's sibling union { __m128; uint64[2]; }; and memcpy, there's accessing fields of __m128. There's __m128i _mm_load_si128(__m128i *p);, but I'm not seeing a _mm_get_* function. Am I missing something? If there's a _mm_set_epi64 then there must be a non-cast way to get the uint64_ts back out, right? (Otherwise why would they bother providing _mm_set_epi64?)
I see Get member of __m128 by index? but the "correct answer" has a broken link and implies there's a load function, but all the loads I see map __m128 to __m128. Shouldn't there be a void _mm_get_epi64(__m128, uint64_t* outbuf)?

Null-aware operator when traversing a nested map [duplicate]

This question already has answers here:
Null-aware operator with Maps
(7 answers)
Closed 3 years ago.
How do you check for nulls when accessing second level map elements?
E.g.
var clientName = item['client']['name'];
will throw an exception if item does not contain client
I'd like something like
item['client']?['name']
or
item['client']?.['name']
But that won't compile.
Surely I can do item['client'] twice or introduce a local var for it but that feels subpar.
I think that this is similar to a question I asked some time ago.
Basically, this would be the solution for your case:
(item['client'] ?? const {})['name']
This makes use of the null-aware ?? operator which just returns an empty map in the case that 'client' is not present in item.
With putIfAbsent, you can use ? operator.
item.putIfAbsent("client", (){})
?.putIfAbsent("name", (){});
https://api.dartlang.org/stable/2.3.1/dart-core/Map/putIfAbsent.html

Trying to understand a "C-style" statement in swift 3 [duplicate]

This question already has answers here:
Swift 3 for loop with increment
(5 answers)
Replacement for C-style loop in Swift 2.2
(4 answers)
Express for loops in swift with dynamic range
(2 answers)
Closed 5 years ago.
I am self-learning to program and I came across this piece of Swift 2.0 code.
someFunction {
for var i = N; i >= 1; i -= 1 {
//...
}
}
This is a "C-Style" code apparently. What exactly is happening in this control flow? Are we starting from N, and subtracting 1 until we get to equal/greater than 1?
Or does the i >= 1 mean that the iteration count must ALWAYS be greater than or equal to one?

Creating byte buffers in rust [duplicate]

This question already has answers here:
Creating a vector of zeros for a specific size
(4 answers)
Closed 7 years ago.
What is the most efficient way to get access to &mut [u8]? Right now I'm borrowing from a Vec but it would be easier to just allocate the buffer more directly.
The best I can do right now is to preallocate a vector then push out its length but there is no way this is idiomatic.
let mut points_buf : Vec<u8> = Vec::with_capacity(points.len() * point::POINT_SIZE);
for _ in (0..points_buf.capacity()) {
points_buf.push(0);
}
file.read(&mut points_buf[..]).unwrap();
You could just create the vec with a given size directly:
vec![0; num_points]
Or use iterators:
repeat(0).take(num_points).collect::<Vec<_>>()

Table elements executing a function [duplicate]

This question already has answers here:
Search for an item in a Lua list
(12 answers)
Lua find a key from a value
(3 answers)
Closed 9 years ago.
I have this table:
maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}
How can I make a script so if 1702169 (for example) is picked from the table, it prints ''That's the number''?
The easiest way to do what (i think) you want is with pairs() function. This is a stateless iterator which you can read more about here: http://www.lua.org/pil/7.3.html
If you simply want to scan through the entire table and see if it contains a value, then you can use this simple code:
local maps = {4707191, 4747722, 1702169, 3994471, 4708958, 4008546, 4323335, 4516043, 4612295, 3469987, 4337892, 238378, 3088188, 329627, 3526384, 433483}
local picked = 1702169
for i, v in pairs(maps) do
if v == picked then
print("That's the number")
break
end
end
The above code will iterate through the whole table where i is the key and v is the value of the table[key]=value pairs.
I am slightly unclear about your end goal, but you could create this into a function and/or modify it to your actual needs. Feel free to update your original post with more information and I can provide you with a more specific answer.

Resources