How to fix 'the arguments to the parameterized interface are not valid' error of IDL file in WinRT? - winrt-async

I'm getting "the arguments to the parameterized interface are not valid" error when trying to write IDL file for my Windows Runtime Component class.
The RunAsync() function returns winrt::Windows::Foundation::IAsyncOperation in my header and I translated it to winrt.Windows.Foundation.IAsyncOperation as https://learn.microsoft.com/en-us/uwp/winrt-cref/winrt-type-system states that UInt32 is "fundamental type" and "[WinRT fundamental types] are permitted to appear in the argument list for a parameterized type".
//ConnectTask.idl
namespace NOVAShared
{
[default_interface]
runtimeclass ConnectTask
{
ConnectTask();
winrt.Windows.Foundation.IAsyncOperation<UInt32> RunAsync();
};
}
//ConnectTask.h
namespace winrt::NOVAShared::implementation
{
struct ConnectTask : ConnectTaskT<ConnectTask>
{
ConnectTask() = default;
static winrt::Windows::Foundation::IAsyncOperation<uint32_t> RunAsync();
};
}
Is my syntax wrong? I've found some random examples of IDL files and it seems right...

The error message of the MIDL compiler is a fair bit misleading. When you compile the following IDL file
namespace NS
{
runtimeclass MyType
{
foo<UInt32> bar();
}
}
you'll get this error message:
error MIDL5023: [msg]the arguments to the parameterized interface are not valid [context]: foo
However, it's not the argument that's invalid. It's the parameterized type (foo) that's unknown. In your case that's winrt.Windows.Foundation.IAsyncOperation. A type with that name does not exist. The Windows Runtime type name is Windows.Foundation.IAsyncOperation instead (which gets projected into the winrt namespace in C++/WinRT, i.e. winrt::Windows::Foundation::IAsyncOperation).
To fix the issue, use the following IDL file:
//ConnectTask.idl
namespace NOVAShared
{
[default_interface]
runtimeclass ConnectTask
{
ConnectTask();
Windows.Foundation.IAsyncOperation<UInt32> RunAsync();
};
}
Note that if you want a static class member, you will have to use the static keyword in IDL.

Related

How to initialize structure in flash at compile time?

I'm working on an embedded C project and would like to initialize, at compile-time, a structure that is stored in flash (0x1200u), but I keep getting weird compile errors.
typedef struct {
float foo[2];
...other stuff...
} MY_STRUCT_DATA_TYPE
#define MY_FLASH_STRUCT ((MY_STRUCT_DATA_TYPE *)(0x1200u)) // <-- error here
MY_FLASH_STRUCT MY_InitdStruct = {
.foo[0] = 0.12345f;
.foo[1] = 0.54321f;
...other stuff...
};
The error I'm getting is "expected '{' before '(' token." Anyone know how to make this work?
Update
Added to linker file...
MEMORY
{
... other stuff ...
m_my_data_section (RW) : ORIGIN = 0x00001200, LENGTH = 0x00000400
... other stuff ...
}
SECTIONS
{
... other stuff ..
.my_data_section :
{
. = ALIGN(4);
KEEP(*(.my_data_section))
. = ALIGN(4);
} > m_my_data_section
... other stuff ...
}
C code...
static volatile const MY_STRUCT_DATA_TYPE __attribute__ ((section (".my_data_section"))) MY_InitdStruct = {
.foo[0] = 0.12345f;
.foo[1] = 0.54321f;
...other stuff...
};
I'm not sure the static or const keywords are necessary, since it's intended only for one-time use to initialize that section of flash memory at compile-time, but it doesn't hurt to restrict the label's usage.
That makes no sense at all, syntactically that is.
What you need to do is figure out how your compiler supports this, since it's not something you can do with just standard C.
With GCC, you use __attribute() to put the symbol in a particular segment, then use the linker script to put that segment in a particular piece of actual memory.
Or, just give your compiler the benefit of the doubt and try a static const structure, that should end up in flash.
In the example you gave, a ";" is missing after the declaration of MY_STRUCT_DATA_TYPE
typedef struct {
float foo[2];
...other stuff...
} MY_STRUCT_DATA_TYPE;
If it's not a copie/paste mistake, it's the kind of error which could lead to the type of error message you have
I'm working on an embedded C project and would like to initialize, at
compile-time, a structure that is stored in flash (0x1200u), but I
keep getting weird compile errors.
That's unsurprising, as C does not support what you're trying to do. You can provide initializers for objects that C allocates, including pointers, but the C language has no concept of objects that exist independently. Indeed, C makes no guarantees whatever about what happens when you do anything with (MY_STRUCT_DATA_TYPE *)(0x1200u) other than convert it back to an integer.
The error I'm getting is "expected '{' before '(' token."
The compiler is complaining because in
MY_FLASH_STRUCT MY_InitdStruct = {
, the expansion of MY_FLASH_STRUCT is not a type, therefore the construct is not a valid declaration. Nor is it a valid assignment, but even if it were, assignment statements are executable, and therefore may appear only inside functions.
Assigning an object to a specific address would be a function of the linker. Whether you can assign an object to the particular address you want is system-dependent, and the mechanism, if any, for doing so depends on your toolchain.

Z3_mk_config and Z3_mk_context deprecated (Z3 C API). Which functions should we use now?

I'm using the C API of Z3. I've checked the examples, and Z3_mk_config() and Z3_mk_context (Z3_config c) are used to create contexts, e.g.,
Z3_config cfg;
Z3_context ctx;
cfg = Z3_mk_config();
Z3_set_param_value(cfg, "model", "true");
//...
ctx = Z3_mk_context(cfg);
However, the documentation says that all these functions are deprecated, but don't mention which functions should be used now instead.
Does anyone know which functions should be used now to create configurations and contexts?
Any help would be greatly appreciated. Thank you!
TLDR:
Use Z3_mk_config to create a Z3_config.
Use Z3_global_param_set to set configs globally.
Use Z3_set_param_value to set context-specific configs.
If you don't have any config to set, simply
make a Z3_config with Z3_mk_config,
create your context with it,
and then delete it with Z3_del_config.
The comment by SergeyLebedev is probably referencing to this remark in the doc
In previous versions of Z3, the Z3_config was used to store global and
module configurations. Now, we should use Z3_global_param_set.
I was going through the source repo the past few days. In the example file test_capi.c, they use this mk_context function a lot, which is defined in the same file with
Z3_context mk_context()
{
Z3_config cfg;
Z3_context ctx;
cfg = Z3_mk_config();
ctx = mk_context_custom(cfg, error_handler);
Z3_del_config(cfg);
return ctx;
}
where mk_context_custom is defined in the same file with
Z3_context mk_context_custom(Z3_config cfg, Z3_error_handler err)
{
Z3_context ctx;
Z3_set_param_value(cfg, "model", "true");
ctx = Z3_mk_context(cfg);
Z3_set_error_handler(ctx, err);
return ctx;
}
So it looks like Z3_mk_config and Z3_set_param_value are still used.
The doc says that stuff like Z3_config and Z3_context are supposed to be "opaque pointers". However, chasing it to the source, it looks like Z3_config is declared as a struct without the specific content but seems like wherever it's used it's cast to context_params which is defined clearly as a class.
The type Z3_config is declared in z3_api_h with
DEFINE_TYPE(Z3_config);
where DEFINE_TYPE(T) is a macro defined in z3_macros.h and expands to typedef struct _ ## T *T. So really Z3_config is only prototypically declared as a struct.
The function Z3_mk_config, the constructor for a Z3_config, declared in z3_api.h with
Z3_config Z3_API Z3_mk_config(void);
, is defined in api_config_params.cpp as
Z3_config Z3_API Z3_mk_config(void) {
try {
memory::initialize(UINT_MAX);
LOG_Z3_mk_config();
Z3_config r = reinterpret_cast<Z3_config>(alloc(context_params));
RETURN_Z3(r);
} catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
warning_msg("%s", ex.msg());
return nullptr;
}
}
within an extern "C" block. Note that Z3_API is a macro also defined in z3_macros.h to set __attribute__ ((visibility ("default"))) and alloc is a macro defined in memory_manager.h with #define alloc(T,...) new (memory::allocate(sizeof(T))) T(__VA_ARGS__) and RETURN_Z3 is a macro defined in some file generated by the file update_api.py with #define RETURN_Z3(Z3RES) if (_LOG_CTX.enabled()) { SetR(Z3RES); } return Z3RES.
It appears that, when a Z3_config is created, a memory block of the size of a context_params is allocated and cast as Z3_config, and context_params is in fact a class defined clearly in context_params.h. I omit the content because it's not relevant right now.
class context_params {
....
};
Next, Z3_set_param_value is defined in api_config_params.cpp with
void Z3_API Z3_set_param_value(Z3_config c, char const * param_id, char const * param_value) {
LOG_Z3_set_param_value(c, param_id, param_value);
try {
context_params * p = reinterpret_cast<context_params*>(c);
p->set(param_id, param_value);
}
catch (z3_exception & ex) {
// The error handler is only available for contexts
// Just throw a warning.
warning_msg("%s", ex.msg());
}
}
So it appears that the function first cast Z3_config back to context_params before using it like a normal object. I'm not an expert but this probably works because struct and class are almost the same underneath the hood.
On the other hand, in that exmaple file test_capi.c, they used Z3_global_param_set like so
....
cfg = Z3_mk_config();
....
/*
The current model finder for quantified formulas cannot handle injectivity.
So, we are limiting the number of iterations to avoid a long "wait".
*/
Z3_global_param_set("smt.mbqi.max_iterations", "10");
ctx = mk_context_custom(cfg, error_handler);
Z3_del_config(cfg);
s = mk_solver(ctx);
They did still use Z3_mk_config before making a context while using Z3_global_param_set to set configs. So I'd say there's nothing wrong with using Z3_mk_config to construct a Z3_config, and what the doc is saying is when you want to set something globally, don't access the Z3_config struct itself since you can't before casting it to a context_params anyway; use Z3_global_param_set instead. And when you want to set something specific to some specific context, use Z3_set_param_value.
The question remains that why would we want to switch between structs and classes? I don't know. I'm not at all familiar with C++, but I'm guessing, if not for the C API itself, it's for making the extern "C" part works for the Python API bindings.

Unable to put strings in an array after initialisation - CCS 6 with TI compiler 5.1.8 for ARM

I'm trying to setup a multilanguage GUI for an application running on AM335x processor; developing in CCS 6.0.1 and using TI compiler 5.1.8. The concept is to get enumerated dictionary arrays and then switch current dictionary pointer to one of them, so that Im able to use enums that make sense.
enum dictionary_indexes {
name,
surname,
phone
}
const char *dictionary_en[60];
dictionary_en[name] = "Your name";
dictionary_en[surname] = "Your surname";
//and so on
Unfortunately, CCS wont compile such code. Itll only allow array initialized at the moment of declaration:
//compiles nicely:
const char * const teststring[] = {
"String1",
"String2",
};
//doesn't compile:
const char *teststring2[2];
teststring2[0]="Hello";
teststring2[1]="World";
Such code results in an error
a value of type "char [6]" cannot be used to initialize an entity of type "int [0]"
and so for every array entry.
Am I missing something here? I've used such code in the past and worked fine. Is it a compiler issue with TI, or is the issue specific for the processor? The code that is supposed to be working is based on this thread: How do I create an array of strings in C?
The teststring2 has to be a global variable, but its init can't. A little rafactor to enclose the init in an executable funciton brings relief and proper compilation, as suggested by #barakmanos.
const char *teststring2[2];
void initDict(){
teststring2[0]="Hello";
teststring2[1]="World";
}
A C file, a translation-unit, can only contain two types of elements (after pre-processing): function-definition's and declaration's. A declaration provides the type of an object and an optional initializer. What you have are statement's, which are only allowed inside a function-definition.
In other words, you need to provide the initialization at the point of declaration, or move them inside a function as an ordinary assignment. Eg:
enum dictionary_indexes {
name,
surname,
phone
}
const char *dictionary_en[60] = {
[name] = "Your name",
[surname] = "Your surname"
};
or:
void f (void)
{
dictionary_en[name] = "Your name";
dictionary_en[surname] = "Your surname";
}
Note that the { [name] = ..., } syntax in initializers was introduces in C99. If you have a compiler that conforms to an earlier standard, you need to initialize the array without designator's and in the correct order:
const char *dictionary_en[60] = {
"Your name",
"Your surname"
};

Confusion about static function pointer in c

Look at the the following code snippet. It was written in 2005 but I am compiling it with latest gcc.
xln_merge_nodes_without_lindo(coeff, cand_node_array, match1_array, match2_array)
sm_matrix *coeff;
array_t *cand_node_array, *match1_array, *match2_array;
{
node_t *n1, *n2;
sm_row *row1, *row2;
static sm_row *xln_merge_find_neighbor_of_row1_with_minimum_neighbors();
while (TRUE) {
row1 = sm_shortest_row(coeff);
if (row1 == NIL (sm_row)) return;
n1 = array_fetch(node_t *, cand_node_array, row1->row_num);
row2 = xln_merge_find_neighbor_of_row1_with_minimum_neighbors(row1, coeff);
n2 = array_fetch(node_t *, cand_node_array, row2->row_num);
array_insert_last(node_t *, match1_array, n1);
array_insert_last(node_t *, match2_array, n2);
xln_merge_update_neighbor_info(coeff, row1, row2);
}
}
While compiling,it complains,
xln_merge.c:299:18: error: invalid storage class for function ‘xln_merge_find_neighbor_of_row1_with_minimum_neighbors’
(xln_merger.c:299 is line 3 here after definition starts).
Line 3 function definition seems to be a function declaration (isn't it???). Does the programmer intended to write a function pointer (static)? Or some syntax has changed over the time in c why this is not compiling.
This code is from sis package here
At least for GCC it will give the "invalid storage class for function" if there is a broken declaration in an included file. You may want to go back to your header files and look for what was intended to be a declaration and instead is a hanging function such as
in included xxx.h file:
void foo(int stuff){ <<<<<<<<< this is the problem, replace { with ;
void bar(uint other stuff);
the open "{" really confuses GCC and will throw random errors latter. It is real easy to do a copy and paste of a function and forget to replace the { with a ;
Especially, if you use my beloved 1TBS
I faced the same problem as the error message keep on say that:
libvlc.c:507:11: warning: “/*” within comment
libvlc.c:2154: error: invalid storage class for function ‘AddIntfInternal’
libvlc.c:2214: error: invalid storage class for function ‘SetLanguage’
libvlc.c:2281: error: invalid storage class for function ‘GetFilenames’
libvlc.c:2331: error: invalid storage class for function ‘Help’
libvlc.c:2363: error: invalid storage class for function ‘Usage’
libvlc.c:2647: error: invalid storage class for function ‘ListModules’
libvlc.c:2694: error: invalid storage class for function ‘Version’
libvlc.c:2773: error: invalid storage class for function ‘ConsoleWidth’
libvlc.c:2808: error: invalid storage class for function ‘VerboseCallback’
libvlc.c:2824: error: invalid storage class for function ‘InitDeviceValues’
libvlc.c:2910: error: expected declaration or statement at end of input
The Simple Fix to this problem is "there is some brace missing in the file from which I am getting these errors."
Just go through the below example.
For example:
#include<stdio.h>
int test1()
{
int a = 2;
if ( a == 10)
{
}
will give
test.c:7: error: expected declaration or statement at end of input
Following the "invalid storage class for function" errors.
So.. Just keeping a watch on the braces could probably resolve this error.
Though uncommon, it's completely valid and standard to declare a function inside another one. However the static modifier makes no sense in a declaration without a body, and you can't* define your function inside another function.
Does the programmer intended to write a function pointer (static)?
I can't know the original programmer's intentions but in no way can that be a function pointer since there's no assignment to it.
* Actually you can as a GCC extension

C++ Constructor With Parameters Won't Initialize, Errors C2059 and C2228

I'm a C# programmer trying to muddle through C++ to create a Windows Forms Application.
I have a Windows Form that makes use of a user-created class. Basically I'm trying to use a constructor that takes parameters, but my form won't let me initialize the object with parameter. Here's the code, hopefully somebody can explain the problem to me because I'm completely baffled...
Here's my header file: BankAcct.h
public ref class BankAcct
{
private:
int money;
public:
BankAcct();
BankAcct(int);
void Deposit(int);
void GetBalance(int&);
};
And my definition file: BankAcct.cpp
#include "StdAfx.h"
#include "BankAcct.h"
BankAcct::BankAcct()
{
money = 0;
}
BankAcct::BankAcct(int startAmt)
{
money = startAmt;
}
void BankAcct::Deposit(int depAmt)
{
money += depAmt;
}
void BankAcct::GetBalance(int& balance)
{
balance = money;
}
And finally my main form. Won't copy the whole thing, of course, but I'm trying to declare the new bank account object, and start it with a balance of say $50.
private:
BankAcct myAccount(50); //does not work! WHY??
//private:
//BankAcct myAccount; //works
then in the form constructor my code is this:
public:
frmBank(void)
{
InitializeComponent();
int bal;
myAccount.GetBalance(bal);
lblBankBalance->Text += Convert::ToString(bal);
}
I've included the BankAcct.h file at the top of my frmBank.h, what else am I doing wrong here? It works great if I use the default constructor (the one that starts the bank balance at zero). I get the following error messages:
error C2059: syntax error: 'constant'
and
error C2228: left of '.GetBalance' must have class/struct/union
Thank you for any and all help on this one!!
C#-style initialization does not work in C++. You need to put initializers in the initialization section of your constructor (i.e. between : and the opening brace { of the constructor:
public:
MyForm() : myAccount(50) {
// Your constructor
}
private:
BankAcct myAccount;
The way you have it now, myAccount is not defined as BankAcct, so calls of GetBalance do not compile either.
One easy workaround:
private:
BankAcct *myAccount; // Make this a pointer
... then ...
frmBank(void)
{
InitializeComponent();
myAccount = new BankAcct(50);
int bal = myAccount->GetBalance(bal);
lblBankBalance->Text += Convert::ToString(bal);
There are other approaches, too. But I think explicitly creating the "myAccount" object is arguably the clearest and simplest. IMHO...

Resources