i am new to the Esp Idf and a beginner programmer and I would like to initialize the adc adc_channel_t via a pointer string but I get an error "conflicting type qualifiers"
can someone help me how to initialize adc_channel_t via own variable so that I can pass in that variable via a own function wehre I can change the channel as argument.
this is the code
const char *ptr ="ADC_CHANNEL_0";
static const adc_channel_t ptr;
adc1_config_channel_atten(ptr, atten);
Thanks
The documentation for adc1_config_channel_atten() can be found in the ESP IDF programming guide.
First of all, you are declaring the ptr variable twice with two different types. That doesn't work. You can declare the variable only once.
Second, you'll see from the documentation that adc1_config_channel_atten expects the enum type adc1_channel_t as type of the first parameter. You can not pass a const char* there. If you have to use a string for whatever reason, you need to write a custom conversion function which takes the string as an argument and returns a variable of the type adc1_channel_t (or an error value, if something can go wrong).
Hope this helps! Let us know in the comments if something is unclear.
Related
cuDeviceGetGraphMemAttribute() takes a void pointer to a result variable. But - what type does it expect the pointed-to value to be? The documentation (for CUDA v12.0) doesn't say. I'm guessing it's an unsigned 64-bit type, but I want to make sure.
For all current attributes you can get with this function, the void * must point to a cuuint64_t.
Thanks goes to #AbatorAbeter for pointing out where this is stated.
I have a structure containing a void pointer but when I need to view the contents of this pointer, I want it to be displayed as a pointer of a particular type. Is there a means to do this within Lauterbach? I tried using the symbol.AddInfo.Type command but it doesn't work as I expect.
I suggest to use a cast operator directly in the watch window.
E.g.: Var.AddWatch (struct struct1 *)pLinkedListBuf
I'm currently trying to learn GO and mainly knowing and working with Java, ASP.Net and some Python, there is no experience working with C-like pointers, which causes my current confusion.
A library I'm currently using to write my first GO project is called Commando.
There I have the struct CommandRegistry and the variable of interest is called Commands.
In the struct the variable is described as the following:
// registered command configurations
Commands map[string]*Command
On a first glimpse I would understand this as a Map object containing a list of Strings, however it also shows the pointer reference to the actual Command object.
All I can see is that it is a map I can loop over which returns the name of the command ( the string ),
however I'm wondering if the *Command in the type description means I can somehow dereference the pointer and retrieve the object itself to extract the additional information of it.
As I know the & operand is used to create a new pointer of another object. Pass-by-reference basically instead of pass-by-value.
And the * operand generally signals the object is a pointer or used to require a pointer in a new function.
Is there a way I can retrieve the Command object or why does the type contain the *Command in it's declaration?
Commands is a map (dictionary) which has strings as keys, and pointers to Commands as values. By passing it a key, you will get a pointer to the command it belongs to. You can then dereference the pointer to an actual Command object by using the * operator. Something like dereferencedCommand := *Commands["key"].
The * operator can be quite confusing, at least it was for me. When used as a type it denotes that we are receiving the memory address of some variable. But to dereference a memory address to a concrete type, you also use the * operator.
I am reading attach_pid function in linux kernel.
Its code is like following:
{
struct pid_link *link;
link = &task->pids[type];
link->pid = pid;
hlist_add_head_rcu(&link->node, &pid->tasks[type]);
}
I do not understand why it does not set pointer directly like this: task->pids[type]->pid = pid.
Why it copy task->pids into link variable and read link variable again?
I found many code that copy pointer into a variable and read indirectly.
Does it have synchronous problem or is it good for code reading?
Probably just save us from dereferencing &task->pids[type] again latter when calling hlist_add_head_rcu(). But smart compilers should be able to do this by itself.
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(...)