I have this compiler error related to "in expansion of macro ‘CHKERRQ’" from PETSC whenever I call "CHKERRQ", I am not sure what causes it, could anyone please give any advice?
Thanks for your help in advance,
Feng
I solved the problem in the end. The return type of my function is void. I need to set the return type of my function, which calls lots of PETSC routines, to PetscErrorCode.
Related
A question for CMake experts out-there.
According to the CMake function documentation a function simply does not return anything. To change variable values one has to pass it to the function, and inside the function set the new value specifying the PARENT_SCOPE option.
Fine, this is a well-known feature of CMake.
My question here is not about the how, rather on why: why CMake functions do not return values? What is the idea behind?
For example, a function cannot be used inside a if expression, or called inside a set command.
If I remember correctly, it is the same with autotools, therefore I do not think it is like this just by chance.
Is there any expert that knows why?
You can find a partial answer by Ken Martin in a message from the CMake's mailing list:
With respect to the general question of functions returning values it
could be done but it is a bit of a big change. Functions and commands
look the same (and should act the same IMO) to the people using them.
So really we are talking about commands returning values. This is
mostly just a syntax issue. Right now we have
command(arg arg arg
)
to support return values we need something that could handle
command (arg command2(arg arg) arg arg
)
or in your case
if(assertdef(foo))
or in another case
set(foo get_property(
))
etc. This hits the parser and the argument processing in CMake but I
think it could be done. I guess I’m not sure if we should do it.
Open to opinions here.
I want to return a Forward_Iterator over the elements of an hashed_set in Ada, like in the code below:
with Ada.Containers.Hashed_Sets;
with Ada.Strings.Unbounded; use Ada.Strings.Unbounded;
with Ada.Strings.Unbounded.Hash;
with Ada.Text_IO; use Ada.Text_IO;
procedure debug is
package my_set is new Ada.Containers.Hashed_Sets
(Element_Type => Unbounded_String,
Hash => Ada.Strings.Unbounded.Hash,
Equivalent_Elements => "=");
function get_Iterator
(some_set : my_set.set)
return my_set.Set_Iterator_Interfaces.Forward_Iterator'Class is --' Highlight fix
begin
return some_set.Iterate;
end;
set_1 : my_set.set;
begin
set_1.insert(To_Unbounded_String("element"));
for E in get_Iterator (some_set => set_1) loop
put_line ("i iterate!");
end loop;
end debug;
The problem is that the code raises a program error
"raised PROGRAM_ERROR : debug.adb:6 finalize/adjust raised exception" which i do not understand ... (im using GNAT Ada GPL 2014 under Ubuntu 14.04)
Is there a way to repair the code? Or is there another possibility to return an iterator over a hashed_set? An application for this is e.g. the case when the hashed_set is part of an private record and it should only be possible to iterate the elements from outside, but not to change the set itself.
Thanks in advance!
PS: This is my first question here, so if you have any tips for improving the question, please tell me :)
I think you have found a bug in GNAT. Please submit your example to the GCC bug database.
But why do you want an explicit iterator object? Usually you just loop over the container leaving the compiler to mess with handling the iterator object.
I just wanted to post my solution to this problem.
I had the possiblity to check the problem with Gnat Pro 7.2.x and I does not appear anymore. But If you do I similar approach using a Hashed_Map instead of a Hashed_Set, it was still there.
Since I also got access to the GNATtracker, I postet my problem there and was told that this is indead a compiler bug. The compiler is generating an incorrect accessibility check at the Get_Iterator function.
Hence, the workaround that was suggested, was to just suppress the corresponding check for the function:
function get_Iterator
(some_set : my_set.set)
return my_set.Set_Iterator_Interfaces.Forward_Iterator'Class is --' Highlight fix
pragma Suppress (Accessibility_Check); -- workaround to suppress buggy check
begin
return some_set.Iterate;
end;
This workaround works for me with Gnat Pro 7.2.x and Gnat GPL 2014 for both, Hashed_Sets and Hashed_Maps.
I've made a large program that opens and closes files and databases, perform writes and reads on them etc among other things. Since there no such thing as "exception handling in go", and since I didn't really know about "defer" statement and "recover()" function, I applied error checking after every file-open, read-write, database entry etc. E.g.
_,insert_err := stmt.Run(query)
if insert_err != nil{
mylogs.Error(insert_err.Error())
return db_updation_status
}
For this, I define db_updation_status at the beginning as "false" and do not make it "true" until everything in the program goes right.
I've done this in every function, after every operation which I believe could go wrong.
Do you think there's a better way to do this using defer-panic-recover? I read about these here http://golang.org/doc/articles/defer_panic_recover.html, but can't clearly get how to use them. Do these constructs offer something similar to exception-handling? Am I better off without these constructs?
I would really appreciate if someone could explain this to me in a simple language, and/or provide a use case for these constructs and compare them to the type of error handling I've used above.
It's more handy to return error values - they can carry more information (advantage to the client/user) than a two valued bool.
What concerns panic/recover: There are scenarios where their use is completely sane. For example, in a hand written recursive descent parser, it's quite a PITA to "bubble" up an error condition through all the invocation levels. In this example, it's a welcome simplification if there's a deferred recover at the top most (API) level and one can report any kind of error at any invocation level using, for example
panic(fmt.Errorf("Cannot %v in %v", foo, bar))
If an operation can fail and returns an error, than checking this error immediately and handling it properly is idiomatic in go, simple and nice to check if anything gets handled properly.
Don't use defer/recover for such things: Needed cleanup actions are hard to code, especially if stuff gets nested.
The usual way to report an error to a caller is to return an error as an extra return value. The canonical Read method is a well-known instance; it returns a byte count and an error.
But what if the error is unrecoverable? Sometimes the program simply cannot continue.
For this purpose, there is a built-in function panic that in effect creates a run-time error that will stop the program (but see the next section). The function takes a single argument of arbitrary type—often a string—to be printed as the program dies. It's also a way to indicate that something impossible has happened, such as exiting an infinite loop.
http://golang.org/doc/effective_go.html#errors
Our code has a lot of the following:
EndpointConfig.cs:
Configure.Instance.Configurer.ConfigureComponent<Foo>(ComponentCallModelEnum.None);
Configure.Instance.Configurer.ConfigureComponent<Bar>(ComponentCallModelEnum.None);
etc, which gives compiler warnings that the ConfigureComponent method is obsolete.
What is the non-obsolete way of doing this?
Replace ComponentCallModelEnum with the appropriate DependencyLifecycle.X
I'm finishing a Scilab project for school, and I've added comments to all my function based on this passage from the documentation:
Inside a function, the first comment lines, up to the first instruction or an empty line may be used to provide the default contents for the function help.
Yet help does not display the comments when I type help myfunction. Instead, it launches the help browser, on the search page.
Any ideas? Basically I'm looking for an equivalent of Matlab's "H1 lines" and "Help text".
The right instruction is
head_comments myfunction
When there is no native function named myfunction and myfunction is known as a user-defined one, indeed it would be fine to use directly
help myfunction
This wish is reported # http://bugzilla.scilab.org/10785
You have to use this function to convert comments to a help page:
http://help.scilab.org/docs/current/en_US/help_from_sci.html
and then compile it.