What does an identifier followed by a colon mean in Objective-C? - ios

bail:
if ( err && image ) {
CGImageRelease( image );
image = NULL;
}
if ( provider ) CGDataProviderRelease( provider );
if ( colorspace ) CGColorSpaceRelease( colorspace );
*imageOut = image;
return err;
I looked at some code and found this. I have never seen this before. What does bail: mean?
It comes from here.

It's a label that the goto statement jumps to.
The code you're looking at, SquareCamViewController.m, uses a macro named require, like this:
require( error == nil, bail );
This macro is defined in the AssertMacros.h header file. It takes a label as its second argument, and uses goto if the first argument evaluates to false.
Using goto to jump to cleanup code at the end of a function is the most common use of goto and labels in C.

bail: is a label. This is standard C syntax. It's not used very often in properly written code. It's most common use is with goto. Please avoid using goto. In the code you referenced it is used by the require function. If the require fails, the code will jump ahead to the bail label, skipping all of the other code in between.

Related

Does ARMv8's ret clear the nzvc register?

Does ARMv8's ret instruction clear the nzvc register?
From the document I couldn't find it, but compiling a code that does 192-bit integer addition using llc-14 sets the flag using adcs: https://godbolt.org/z/zWo6GKsE7
No. ret does nothing except branch to x30 (or whatever other register you pass it).
The manual defines its operation as:
bits(64) target = X[n, 64];
// Value in BTypeNext will be used to set PSTATE.BTYPE
BTypeNext = '00';
BranchTo(target, BranchType_RET, FALSE);

How to store AccountBalance() into a variable?

if(Total_sell_pos() == 0 && Total_buy_pos() == 0) {
double previous_balance = AccountBalance(); //usd1000
}
if (AccountEquity() > previous_balance + (previous_balance *0.05)){ //usd1000 + 50 = usd1050
CloseSellOrders();
CloseBuyOrders();
Delete_Pendings();
}
if Equity more than usd1050 then delete pending and orders.
But why when run the code, it keep delete pending and orders immediately even when Equity is less than previous balance?
The following code is the problem, and I replace it :
AccountEquity() > previous_balance + (previous_balance *0.05)
with
AccountEquity() > 1050
then only it works. I did try to check the value :
double check_value = previous_balance + (previous_balance *0.05);
printf (check_value); //1050
May I know why I cannot use the following code?
AccountEquity() > previous_balance + (previous_balance *0.05)
Q: How to store AccountBalance() into a variable?
Let's start with the variable - declare it:
double aPreviousBALANCE;
The scope-of-declaration is driven by the enclosing code-block boundaries. MQL4/5 can declare a variable on the "global"-scope, that may become visible from inside other code-blocks, but if any such has a variable name identical to the "global"-scope defined one, the locally declared ( explicitly in the code, or introduced from the function-parameters' declaration in the call-signature specification ) will "shade-off" the access to the variable declared on the "global"-scope. This you have to check in the original code and MQL4/5-IDE may warn you about such collision(s) during the compilation ( ref. Compiler Warning Messages ).
Let's store in it the actual state, we'll have more steps here:
RefreshRates(); // Force a state-update
aPreviousBALANCE = AccountInfoDouble( ACCOUNT_BALANCE ); // Store an updated value
Q: May I know why I cannot use the following code?
Well, any language, MQL4/5 not being an exception, has some order of execution of mathematical operators. MQL4 need not and does not have the warranty about using the same one as any other language we may have had some prior experience. So, always be rather explicit in this a specify all ordering via explicit parentheses, this will save you any further "surprises" when the language parser / compiler will suddenly change the priority of operators and sudden nightmares will appear. Not worth a single such shock to ever happen:
if ( ( ( a * b ) + c ) < fun() ) // is EXPLICIT and a way safer, than
if ( a * b + c < fun() ) // is DEPENDENT on not having {now|in future}
// a binary boolean (<)-operator
// a higher priority than (+)-op
so, rather be always explicit and you remain on the safer side.
Finally, test:
RefreshRates(); // Force a state-update
if ( ( aPreviousBALANCE * 1.05 ) < AccountInfoDouble( ACCOUNT_EQUITY ) )
{
...
}
Also check, how are your settings pre-set from the Broker-side - they run a Support-Line for you to ask about their settings:
Equity calculation depends on trading server settings.
Print( "Profit calculation mode for SYMBOL[ ",
Symbol(),
" ] is ",
MarketInfo( Symbol(), MODE_PROFITCALCMODE ),
" { 0: mode-FOREX, 1: mode-CFD, 2: mode-FUTURES }."
);
And where is my AccountBalance() function?
Recent Terminal Builds use a set of new types of calls to:
AccountInfo{Integer|
Double|
String}( <anEnumDrivenItemIDENTIFIER>
)
SymbolInfo{Integer|
Double|
String}( <aSymbolNAME>,
<anEnumDrivenItemIDENTIFIER>
)
to name just a few, so re-read the documentation to adopt the most recent changes. Always. ALAP when your Terminal has got a new Build updated ( might be seen when loading a new version of Help files for the MQL4-IDE and/or Terminal ).
Well, this happens. MQL4 evolves and some features we were used to for ages cease to exist, start to suddenly yield inaccurate or indefinite result or change its behaviour ( ol' MQL4-ers still remember the day, when string data type simply ceased to be a string in silence and suddenly started to become a struct. Ok, it was mentioned somewhere deep inside an almost unrelated page of an updated Help-file, yet the code-crashes were painful and long to debug, analyze and re-factor )

How to make a function to read values from the lua file

Well I'm learning lua and I got a question, I'm trying to create a reading function bool in lua.
I have a function that disables or enables as I score true or false.
This function is called just useappenabled that I am not able to apply it on the Moon, before I used in the form of libconfig and functioned normally before was written as follows.
The file is as follows:
Enableapp =
{
Useapp = true;
};
Now reading before shaped libconfig was the following, note that the useappenabled function is applied to the input value, i.e. true or false if I put on the Useapp.
if (config_lookup(&onf, "Enableapp"))
if (config_setting_lookup_bool(cf, "Useapp", &SelectValue))
useappenabled = SelectValue;
So I tried changing the code libconfig to lua, however I am not able to read the useappenabled function, the code is as follows in the lua.
lua_getglobal(L, "Enableapp");
lua_pushstring(L, "Useapp");
lua_tonumber(L, useappenabled);
I believe the problem is lua_tonumber, I need to do something more or less like this:
useappenabled = value_the_Useapp;
But I'm starting lua now, can anybody tell me how can I apply the function useappenabled to equal the Useapp value.
not able to apply it on the Moon
That's an issue with most Earthly software. The usual difficulty is reaching the Moon.
I need to do something more or less like this:
useappenabled = value_the_Useapp;
lua_getglobal(L, "Enableapp"); // push the table onto the stack
lua_getfield(L, -1, "Useapp"); // index table with "Useapp" and push result onto the stack
useappenabled = lua_toboolean(L, -1); // get the value off the top of the stack into your C code

Velocity parse error on a null value

I have a problem in my velocity template.
I have to show the image url for some products.
I set a variable in a right way. In some cases anyway I don't have this image, so I have to hide the image and put a blank space in the template.
I write the set variable in this way:
#set ($variantUrl = ${#if(!$product.getOrderFormImage().getUrl()) $!product.getOrderFormImage().getUrl() #else $product.getOrderFormImage().getUrl() #end} )
but I obtain a parse error:
Caused by: org.apache.velocity.exception.ParseErrorException:
Encountered "(" at
de.hybris.platform.commons.renderer.impl.VelocityTemplateRe
nderer[line 403, column 103] Was expecting:
...
I don't see any error in this line. What's the problem?
I'm not sure you can nest #if #else within #set - at least there's no mention of it in the Velocity user guide.
When I use your original expression I get the following error:
org.apache.velocity.exception.ParseErrorException: Encountered "#if" at ....
Was expecting:
<IDENTIFIER> ...
If I rewrite to make the #if #else to be the top-level statement such as:
#if( !$product.getOrderFormImage().getUrl() )
#set($variantUrl = $!product.getOrderFormImage().getUrl() )
#else
#set($variantUrl = $product.getOrderFormImage().getUrl() )
#end
this seems to do what you want, or at least it compiles and doesn't error! It's also a lot easier to read and understand.
Personally, I'd go one step further for the purpose of readability and use Velocity's shorthand notation for references:
#if( !$product.orderFormImage.url )
#set($variantUrl = $!product.orderFormImage.url )
#else
#set($variantUrl = $product.orderFormImage.url )
#end

Is it safe to use the same parameters for input and output in D3DX functions?

Using the D3DX library that is a part of directX, specifically directx9 in this case, I'm wondering if it's safe to use the same matrix (or vector etc) for input and ouput
D3DXMATRIX mat;
D3DXMatrixInverse(&mat, NULL, &mat);
I've been avoiding doing so, assuming that it would result in bad things happening when parts of the array got partly overwritten as results are calculated but I see an awful lot of code around that does exactly this.
A brief test indicates that it seems to work ok, so I'm assuming that the D3DX functions take a copy where necessary of the input data, or some other method to ensure that this works ok, but I can't find it documented anywhere so I'm reluctant to rely on it working.
Is there any official statement on using the functions like this?
Yes, it is. From msdn:
Each of the functions can take the same object as the passed [in] and returned [out] parameters
I'm pretty sure the answer is yes. I can't find anywhere where this is said for sure however ...
Edit: Flicking through D3DX9Math.inl it looks like care HAS been taken to make sure you can. For example if we look at the code for D3DXVec3Cross:
D3DXINLINE D3DXVECTOR3* D3DXVec3Cross
( D3DXVECTOR3 *pOut, CONST D3DXVECTOR3 *pV1, CONST D3DXVECTOR3 *pV2 )
{
D3DXVECTOR3 v;
#ifdef D3DX_DEBUG
if(!pOut || !pV1 || !pV2)
return NULL;
#endif
v.x = pV1->y * pV2->z - pV1->z * pV2->y;
v.y = pV1->z * pV2->x - pV1->x * pV2->z;
v.z = pV1->x * pV2->y - pV1->y * pV2->x;
*pOut = v;
return pOut;
}
You can see that it performs the cross product into a temporary and THEN, in the final step, it copies it into the return. It would be nice if this was stated somewhere for sure.

Resources