I am looking for preprocessor directive to disable compiler warnings for desired block of code in MQL4.
I have some bitwise IFs and don't want to cast everything explicitly like:
if ( (bool)(flag & 0x00110101) ) {}
Instead I am looking for something like:
#nowarn
if ( flag & 0x00110101 ) {}
Related
I would like to do something like:
DEFAULT_CLUSTER_ALIASES = {
"local": "$(DEFAULT_LOCAL_CLUSTER)",
}
def helm_action(**kwargs):
if not "$(DEFAULT_LOCAL_CLUSTER)":
DEFAULT_LOCAL_CLUSTER = "docker-desktop"
_helm_action(
cluster_aliases = DEFAULT_CLUSTER_ALIASES,
**kwargs
)
IOW, if DEFAULT_LOCAL_CLUSTER is not defined, DEFAULT_CLUSTER_ALIASES will be dict("local": "docker-desktop").
and if --define=DEFAULT_LOCAL_CLUSTER=minikube, DEFAULT_CLUSTER_ALIASES will be dict("local": "minikube").
So far, I haven't been able to get the Make variable to be evaluated and DEFAULT_CLUSTER_ALIASES is dict("local": "$(DEFAULT_LOCAL_CLUSTER)").
What's needed so the Make variable is evaluated?
"make variables" are only evaluated in the context of rule attributes that support make variable substitution. See https://bazel.build/reference/be/make-variables#use
If helm_action is a macro, or is used from a macro, then this won't work because macros don't have access to configuration information (e.g. values from flags). If helm_action is used from a rule implementation, then you can access values set using --define from ctx.var: https://bazel.build/rules/lib/ctx#var
Another way to do this is to use Starlark flags: https://bazel.build/rules/config#user-defined-build-settings Though again, it depends on if you're writing a macro or a rule.
As per Language specs (10.1.1 Operators) I am trying to override some operators.
I get an analyzer error when overriding the 'minus' and 'unary minus' operators - one that I don't get:
'The operator "-" is not defined on class Indentation'
but in the class I have defined it:
Indentation operator -() {
level--;
return this;
}
and I use it like myInstance--; and it actually does work, but still the analyzer complains and I cannot submit the code 'clean' because of the error.
I have looked up an old thread (Why does overriding negate cause static warning in Dart) but I think it is not relevant here.
Any advise is welcome.
--x is the same as x -= 1. To use it you have to define the operator -(p) (not operator -())
Indentation operator -(n) => new Indentation(level - n);
I'm using the Nimble assertion framework for unit testing in Swift (Xcode 6.3 beta). It works fine, but the compiler gives a warning for one of the lines in the Nimble source code:
public func expect<T>(expression: () -> T?, file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T> {
return Expectation(
expression: Expression(
expression: expression,
location: SourceLocation(file: file, line: line),
isClosure: true))
}
The warning is for the first line:
Closure parameter prior to parameters with default arguments will not
be treated as a trailing closure
It's not a very serious issue, but I'd like to keep the number of compiler warnings low (zero) in my projects. Is there a way to remove this warning?
You can avoid the warning if the method signature will look like:
public func expect<T>(expression: (() -> T?), file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T>
added extra parenthesis around the first argument, tested with Swift 2.0 and Xcode 7.1
Another way of fixing it is to have all attributes with default value before the closure attribute as trailing closure is a quite convenient thing to have
#Julian Król answer is wrong for two reasons:
the code snippet demonstrate the wrong syntax, the correct will be:
public func expect<T>(expression: (() -> T?), file: String = __FILE__, line: UInt = __LINE__) -> Expectation<T>
even with right syntax in Xcode 7.1 it does not fix the issue, cause you can not call this methods with trailing closure- it will give you compile error like Missing argument for parameter #1 in call.
With provided code you will only get rid of warning but you will not be able to use trailing closure when you call this function.
It fixes warning because in Swift tuple with one child is interchangeable with just single variable. And even ((((value)))) is the same as just value. Also looks like compiler does not recognize tuple with closure child as standalone closure in function arguments list.
To all the future readers of this topic: the answer is just for the case, when you have trailing closures. AFAIK, there is no way you can suppress Swift warnings like you would do in Objective-C (disable warnings for specific lines), maybe when the source of the Swift compiler will be open source, there will be some valid solutions, and this answer will be updated. Until then, you can check these answers (not Swift specific):
In Xcode, how to suppress all warnings in specific source files?
Is there a way to suppress warnings in Xcode?
If you can change the signature of expect, then put the parameter expression to the end, like:
public func expect<T>(file: String = __FILE__, line: UInt = __LINE__, expression: () -> T?) -> Expectation<T>
To be honest, it is poor design to have a closure parameter as the first parameter.
Looks like a very serious warning to me, that you most definitely should not ignore. It seems that what you think is a function call with a closure parameter is actually a function call without a closure parameter, followed by a closure.
You easily avoid the warning and fix the problem by putting the closure into the parameter list, or assigning it to a variable before the call and passing that variable.
I'm working on a platform invoke call from F#, and I am getting a compiler error I really can't make that much sense out of. First, let me show the C signature of what I am doing:
int Foo(
ULONG_PTR *phHandle,
DWORD flags
);
In F#, I think the correct way to invoke this natively is as so:
[<DllImport("somedll.dll")>]
static extern int APlatformInvokeCall
(
[<Out>]nativeint& phHandle,
uint32 flags
)
If I try to call this in a class, I get a compilation error when calling it like so:
type Class1() =
[<DllImport("somedll.dll")>]
static extern int APlatformInvokeCall
(
nativeint& phHandle,
uint32 flags
)
member this.Foo() =
let mutable thing = nativeint 0
APlatformInvokeCall(&thing, 0u) |> ignore
thing
The error is:
A type instantiation involves a byref type. This is not permitted by the rules of Common IL.
Weirdly, when I do this all in a module, the compilation errors go away:
module Module1 =
[<DllImport("somedll.dll")>]
extern int APlatformInvokeCall
(
nativeint& phHandle,
uint32 flags
)
let Foo() =
let mutable thing = nativeint 0
APlatformInvokeCall(&thing, 0u) |> ignore
thing
Why does this compile as a module, but not as a class?
I don't think it's valid to define an extern method within a class in F#.
If you pull up the F# 3.0 language specification and search for DllImport, near the bottom is a table listing some special attributes and how they can be used. The text for [<DllImport>] says:
When applied to a function definition in a module, causes the F# compiler to ignore the implementation of the definition, and instead compile it as a CLI P/Invoke stub declaration.
That seems to indicate that it's only valid to declare extern methods (that use [<DllImport>]) on functions defined in a module; it doesn't say anything about class members though.
I think you're running into a compiler bug. Please submit this code to fsbugs#microsoft.com so they can fix the error message emitted by the compiler -- it should really be giving you an error about defining an extern method in a class since that's not allowed by the language spec.
Whether this is a bug not withstanding, maybe this is what's going on: If APlatformInvokeCall were considered a static member function, that member have a single argument of tuple type. Tuples are compiled into objects of generic type (see here, at the bottom, or 5.1.3 in the spec). In this case that tuple is
System.Tuple<nativeint&, uint32>
But ECMA 335 II.9.4 says you can't instantiate generic types at byref types. This explains the error reported.
This explanation fits the fact mentioned above that Class1 works (well, compiles) if you modify the extern declaration and call to take instead a single argument. It also fits the fact that the module version works, since in that version there is no considering APlatFormInvokeCall a member function.
The simple solution is to check the spec, here is the class definition grammar:
type type-name pat_opt as-defn)opt =
class
class-inherits-decl_opt
class-function-or-value-defns_opt
type-defn-elements
end
then we have
class-function-or-value-defn :
attributes_opt staticopt let rec_opt function-or-value-defns
attributes_opt staticopt do expr
which doesn't allow extern.
and
type-defn-element :
member-defn
interface-impl
interface-signature
which isn't what you want either.
As a result, we can see that using extern as you are trying to use it can't be done inside a class.
There are 3 (which I know) ways to suppress the "unused variable" warning. Any particular way is better than other ?
First
- (void)testString:(NSString *)testString
{
(void)testString;
}
Second
- (void)testString:(NSString *)__unused testString
{
}
Third
- (void)testString:(NSString *)testString
{
#pragma unused(testString)
}
This is the approach I use: cross platform macro for silencing unused variables warning
It allows you to use one macro for any platform (although the definitions may differ, depending on the compiler), so it's a very portable approach to express your intention to popular compilers for C based languages. On GCC and Clang, it is equivalent of wrapping your third example (#pragma unused(testString)) into a macro.
Using the example from the linked answer:
- (void)testString:(NSString *)testString
{
MONUnusedParameter(testString);
}
I've found this approach best for portability and clarity, in use with some pretty large C, C++, ObjC, and ObjC++ codebases.
If you are compiling with GCC, you can take advantage of attribute extensions to set the 'unused' attribute. Like this:
int somevar __attribute__((unused));
It also works for unused parameter warnings (-Wunused-parameter)
To make it shorter to write I am using this macro:
#define _U_ __attribute__((unused))
And declare like this:
int somevar _U_ ;
One way to do it is just to assign a variable pointlessly after it is declared For example:
int foo;
foo = 0;
This should suppress the unused variable warning. It is just a pointless assignment.
But otherwise I would agree with ouah, the first method is the most reliable, if you must choose from those three.