Interpretation of undefined returns in expo-file-system? - promise

Some functions in the expo-file-system API can resolve to undefined (as opposed to being rejected), but I can't find any explanation in the docs of how to interpret such a return value. What is the meaning of an undefined return (as opposed to rejection)?

Related

tslint: How to make sure that a variable is not undefined?

As per the following screenshot, the TsLint is claiming that a variable might be undefined which is not assignable to a function's parameter.
But I have already checked and make sure that it's not undefined above passing it as the function's parameter.
Why does TsLint is still claiming that the variable might be undefined?
I can dismiss that warning by changing the code to:
clearTimeout(saveDraftTimer.current as unknown as number)
but it looks ugly, any better suggestion?
const saveDraftTimer = useRef<number | undefined>(undefined);

Recursive variable declaration

I have just seen this black magic in folly/ManualExecutor.h
TimePoint now_ = now_.min();
After I grep'ed the whole library source code, I haven't seen a definition of the variable now_ anywhere else than here. What's happening here? Is this effectively some sort recursive variable declaration?
That code is most likely equal to this:
TimePoint now_ = TimePoint::min();
That means, min() is a static method, and calling it using an instance is same as calling it like this, the instance is used just for determining the type. No black magic involved, that's just two syntaxes for doing the same thing.
As to why the code in question compiles: now_ is already declared by the left side of the line, so when it's used for initialization on the right side, compiler already knows its type and is able to call the static method. Trying to call non-static method should give an error (see comment of #BenVoigt below).
As demonstrated by the fact that you had to write this question, the syntax in the question is not the most clear. It may be tempting if type name long, and is perhaps justifiable in member variable declarations with initializer (which the question code is). In code inside functions, auto is better way to reduce repetition.
Digging into the code shows that TimePoint is an alias for chrono::steady_clock::time_point, where min() is indeed a static method that returns the minimum allowable duration:
http://en.cppreference.com/w/cpp/chrono/time_point/min

DIA SDK how to get parent function of FuncDebugStart / FuncDebugEnd?

The documentation for SymTagFuncDebugStart and SymTagFuncDebugEnd state that calling IDiaSymbol::get_lexicalParent will return a symbol for the enclosing function. I interpret this as I will get an IDiaSymbol whose get_symTag method returns SymTagFunction. However, when I do this it returns me the SymTagCompiland and not the function. So the documentation appears wrong, but worse I'm not sure how to actually tie the SymTagFuncDebugStart and SymTagFuncDebugEnd to the containing SymTagFunction.
Does anyone know? A few dumps suggest that SymTagFuncDebugStart and SymTagFuncDebugEnd always come immediately after the corresponding SymTagFunction when enumerating the symbols via IEnumSymbols. Or put another way, that if IDiaSymbol::get_symIndexId returns n for the function, it will return n+1 and n+2 respectively for the func debug start and func debug end.
But I can't be sure this is always true, and this seems unreliable and hackish.
Does anyone have any suggestions on the correct way to do this?
Could you paste your code here? I guess there is something wrong in your code. Call get_lexicalParent on SymTagFuncDebugStart and SymTagFuncDebugEnd should return the symbol associated the enclosing function (SymTagFunction).
I got this working eventually. The problem is that when you enumerate all the symbols in the global scope using SymTagNull, you will find the FuncDebugStart and FuncDebugEnd symbols. The lexical parent of these symbols is the global scope, because it's the "parent" in the sense that it vended you the pointers to the FuncDebugStart and FuncDebugEnd symbols.
If you get the FuncDebugStart and FuncDebugEnd by calling findChildren on an actual SymTagFunction symbol, however, then its lexical parent will in fact be the original function. So this was an issue of unclear documentation.

undefined reference to `__aeabi_ddiv' and friends - building without stdlib but with -mfloat-abi=hard

I'm trying to build a project for Cortex-M4F. The Chip has a FPU, so I'm building with -mfpu=fpv4-sp-d16 -mfloat-abi=hard and I'm not using any libraries in order to save space, so I do -nostdlib -fno-builtin.
Now I want to use floating point operations, but when doing so I get a linker error:
led1642gw_gain.c:(.text.led_calculateGain+0xc): undefined reference to `__aeabi_f2d'
led1642gw_gain.c:(.text.led_calculateGain+0x24): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0x36): undefined reference to `__aeabi_dsub'
led1642gw_gain.c:(.text.led_calculateGain+0x48): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0x54): undefined reference to `__aeabi_d2f'
led1642gw_gain.c:(.text.led_calculateGain+0x9e): undefined reference to `__aeabi_f2d'
led1642gw_gain.c:(.text.led_calculateGain+0xb6): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0xc8): undefined reference to `__aeabi_dsub'
led1642gw_gain.c:(.text.led_calculateGain+0xda): undefined reference to `__aeabi_ddiv'
led1642gw_gain.c:(.text.led_calculateGain+0xe6): undefined reference to `__aeabi_d2f'
led1642gw_gain.c:(.text.led_calculateGain+0x10c): undefined reference to `__aeabi_f2d'
Why is that? If I understand correctly, it shouldn't have to rely on library functions but use ARMs native FPU instructions for that.
Your core supports single-precision floating point instructions however your code works with double-precision floating point.
You can notice all the missing __aeabi stuff has a 'd' (as in double) mentioned.
If you have floating point literals in your code, by C standard they are considered double. You can force them into single-precision range by adding a f or F at the end of literal.
2.13.3 Floating literals: The type of a floating literal is double unless explicitly specified by
a suffix. The suffixes f and F specify float...
It is well known that in C, floating point literals (e.g. 1.23) have type double. As a consequence, any calculation that involves them is promoted to double.
To solve this, add 'f' to the end of all literals i.e.,
if (x < 2.5) ...
to
if (x < 2.5f) ...

Why can I refer to a variable outside of an if/unless/case statement that never ran?

Why does the following code not throw an error?
if false
x = 0
end
x #=> nil
Whereas the following does throw an error:
y # NameError: undefined local variable or method `y' for main:Object
The same thing happens with unless & case statements.
It's because of how the Ruby parser works. Variables are defined by the parser, which walks through the code line-by-line, regardless of whether it will actually be executed.
Once the parser sees x =, it defines the local variable x (with value nil) henceforth in the current scope. Since if/unless/case/for/while do not create a new scope, x is defined and available outside the code block. And since the inner block is never evaluated as the conditional is false, x is not assigned to (and is thus nil).
Here's a similar example:
defined?(x) and x = 0
x #=> nil
Note that this is a rather high-level overview of what happens, and isn't necessarily exactly how the parser works.
This has to do with a quirk of Ruby's scoping rules.
In ruby, an undecorated variable x appearing by itself could either be a local variable or a method call -- the grammar can't tell which. It's up to the parser to figure it out as it resolves local variable references. The rule is simple: if an assignment to a variable of the same name has been seen already in the local scope, then the reference is a local variable, and the reference is bound to that local variable. Otherwise, it's a method call, and it will be looked up as such at runtime.
Local variable references in Ruby are optimized into array lookups (each local variable is assigned a 'slot', and bound local variable references generated by the parser are converted into slot references). The array is initialized with all nil:
/* initialize local variables */
for (i=0; i < local_size; i++) {
*sp++ = Qnil;
}
Thus, if you refer to a local variable that hasn't been assigned, through a bound local reference (which can only happen if there was a skipped assignment above the reference in the same local scope), you get nil.
I thought your question was interesting so I tried to look it up and found this:
I don't understand ruby local scope
The correct answer seems to be put Jorg.
Lets look at what happens when you try to access a variable that isn't initialized:
NameError: undefined local variable or method `UNDECLAREDVAR' for main:Object
The exception states that it is unavailable to evaluate whether a variable or method. The reason it doesn't throw the same exception is because uninitialized local variables are set to nil. So puts x is a okay because the interpretor knows that x is variable but uninitialized and not a method.

Resources