I am trying to build a game for Arduino, so I searched for a starting point and got to this syntax:
enum DisplayItem upperItem = (DisplayItem)((graphicRam[x/(8/2)][y*2]>>((x%(8/2))*2))&0x3);
where I have the enum variable with it's states:
enum DisplayItem {GRAPHIC_ITEM_NONE, GRAPHIC_ITEM_A, GRAPHIC_ITEM_B, GRAPHIC_ITEM_NUM};
The ((graphicRam[x/(8/2)][y*2]>>((x%(8/2))*2))&0x3) part is from the rest of the code and I think it can be treated as a simple integer. My question is how (DisplayItem)(something) works? I've tried to run a simpler code but this syntax (enum variable)(x) just give me an error.
Related
A snip of Rust code:
pub fn main() {
let a = "hello";
let b = a.len();
let c =b;
println!("len:{}",c)
}
When debugging in CLion, Is it possible to evaluate a function? For example, debug the code step by step, now the code is running to the last line println!... and the current step stops here, by adding the expression a.len() to the watch a variable window, the IDE can't evaluate the a.len(). It says: error: no field named len
This is the same reason you can't make conditional breakpoints for Rust code:
Can't create a conditional breakpoint in VSCode-LLDB with Rust
I hope, I'm not too late to answer this, but with both lldb and gdb, Rust debugging capability is currently rather constrained.
Expressions that are straightforward work; anything complex is likely to produce issues.
My observations from rust-lldb trying this, are that only a small portion of Rust is understood by the expression parser.
There is no support for macros.
Non-used functions are not included in the final binary.
For instance, since that method is not included in the binary, you are unable to execute capacity() on the HashMap in the debugger.
Methods must be named as follows:
struct value.method(&struct value)
There is no technique that I've discovered to call monomorphized functions on generic structs (like HashMap).
For example, "hello" is a const char [5] including the trailing NUL byte. String constants "..." in lldb expressions are produced as C-style string constants.
Therefore, they are not valid functions
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
This is a follow up questions from How to convert typename T to string in c++
I am asking because I would really like to generate nice error messages like
static_assert(one_of<T,Components...>::value,
"Unable to access T because you didn't
use it in filter<Components...>.");
Would print
Unable to access Foo because you did not use it in filter<Bar,Baz,Bat>.
Is something like this now possible in C++11 / 14?
Quoting from the poor(lazy?) man's version of the C++ Standard,
Since message(the second argument to static_assert) has to be a string literal, it cannot contain dynamic information or even a constant expression that is not a string literal itself. Typically, it cannot contain the name of the template type argument.
So, there isn't a way of getting the friendly static_assert error messages you desire.
No, no it is not possible to do that.
I'm getting (fairly reguarly) an "Error 16: Expression too complex" runtime error on a simple assigment to a property from a class.
public property PropertyName() as double
PropertyName = mvarPropertyName
end property
The debug window points to the crash being on the assignment line in the above code.
Some inital reading here and elsewhere suggested that it was related to the line calling the property. However, that now looks like this:
variableName = ObjectName.PropertyName
And all arithmetic is done with variableName.
Even more oddly, if I just hit debug, then resume/F5 immediatley, everything is fine.
Trying to use the error handling code to do this doesn't seem to have worked however.
Any ideas what is causing this error?
Stop using Not (Not MyArray) to test for uninitialized arrays. This uses a bug in the compiler that has a known side effect of destabilizing the run-time leading to "Expression too complex" on random places.
VB6 - Returning/Detecting Empty Arrays is fairly complete thread on different ways to test for empty and uninitialized arrays.
A string expression is too complicated. Strings not assigned to variables (such as those returned by functions) are assigned to temporary locations during string expression evaluation. Having a large number of these strings can cause this error. Try assigning these strings to variables and use the variables in the expression instead.
I have a Swig-wrapped C library that I use in Ruby. I have no control over Swig or any interface definitions since that is done by the vendor of the interface.
No I find that there's a function in the library that has a char ** output parameter defined (among others). Example function definition:
void get_information(char * input, char **output, int someint)
Of course, my first attempt in Ruby was:
output_thing = ''
get_information "input", output_thing, 123
puts output_thing
This resulted in the error message
Expected argument 1 of type char **, but got String ""
Having no experience in Swig, I'm kindof stuck. Is it possible to make use of this function in Swig without defining or using a typemap?
Thanks in advance for your quick responses!
I found it (weee!)
There is a new_charpp method that creates the correct datatype. Apparently you have several of these methods for each of the primitives and commonly used datatypes (new_longpp, new_longlongpp, new_intpp et cetera).
Afterwards, you can read the correct contents from this variable using charpp_value(...)