|
|
Up |
|
|
  |
Author: RaúlRaúl Date: Sep 16, 2008 02:08
Hi,
I am trying to read an external variable which is declared in an
external library, in this case libc. I am doing some libc calls from
my Fortran code and those return the error status in the well known
errno variable of libc.
Checking Fortran forums I realized that to do such thing I have to use
bind modifier in my declaration of the variable. The code is as
follows
module test
use iso_c_binding
integer(c_int), bind(c,name='errno') :: errno
...
...
end module test
This doesn't work for an external library. It works for other objects
but not for libraries. I don't know if it could be because is a
dynamic library and not a static one.
|
| Show full article (0.77Kb) |
|
| | 15 Comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Sep 16, 2008 03:06
Raúl wrote:
> integer(c_int), bind(c,name='errno') :: errno
It is probably best to call a C routine that returns errno.
I believe that it is commonly an ordinary external
variable, but there are other possibilities.
-- glen
|
| |
|
| | no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Sep 16, 2008 02:31
On 16 sep, 11:08, Raúl gmail.com> wrote:
> Hi,
>
> I am trying to read an external variable which is declared in an
> external library, in this case libc. I am doing some libc calls from
> my Fortran code and those return the error status in the well known
> errno variable of libc.
>
> Checking Fortran forums I realized that to do such thing I have to use
> bind modifier in my declaration of the variable. The code is as
> follows
>
> module test
> Â use iso_c_binding
>
> Â integer(c_int), bind(c,name='errno') :: errno
>
> Â ...
> Â ...
> end module test ...
|
| Show full article (1.37Kb) |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Sep 16, 2008 08:06
Arjen Markus wrote:
(snip)
> The easiest way to deal with errno, I'd say, is create a
> small C function along these lines:
>
> void get_errno( int &errno_value ) {
> *errno_value = errno;
> }
or
int get_errno() {
return errno;
}
|
| |
| no comments |
|
  |
Author: Steven G. KarglSteven G. Kargl Date: Sep 16, 2008 07:07
In article comcast.com>,
glen herrmannsfeldt ugcs.caltech.edu> writes:
> Raúl wrote:
>
>> integer(c_int), bind(c,name='errno') :: errno
>
> It is probably best to call a C routine that returns errno.
>
> I believe that it is commonly an ordinary external
> variable, but there are other possibilities.
>
From FreeBSD /usr/include/errno.h,
#ifndef _KERNEL
#include
__BEGIN_DECLS
int * __error(void);
__END_DECLS
#define errno (* __error())
#endif
|
| Show full article (0.63Kb) |
| no comments |
|
  |
Author: nospamnospam Date: Sep 16, 2008 09:04
glen herrmannsfeldt ugcs.caltech.edu> wrote:
> Raúl wrote:
>
>> integer(c_int), bind(c,name='errno') :: errno
>
> It is probably best to call a C routine that returns errno.
>
> I believe that it is commonly an ordinary external
> variable, but there are other possibilities.
As an aside (since I think the problem and solution have been accurately
shown), note that none of this has much of anything to do with being in
a library as the OP thought. Instead, it is specific to errno.
--
Richard Maine | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle | -- Mark Twain
|
| |
| no comments |
|
  |
Author: glen herrmannsfeldtglen herrmannsfeldt Date: Sep 16, 2008 11:42
Steven G. Kargl wrote:
(snip)
> From FreeBSD /usr/include/errno.h,
> #ifndef _KERNEL
> #include
> __BEGIN_DECLS
> int * __error(void);
> __END_DECLS
> #define errno (* __error())
> #endif
> errno is not required to be an int variable.
> It is required to be a modifable lvalue.
In K&R2, the closest I have to a copy of the C89
standard, errno is described as an expression.
It is supposed to be close to the final draft of the
standard, similar to what we have for Fortran 2003.
-- glen
|
| |
| no comments |
|
  |
Author: Steven G. KarglSteven G. Kargl Date: Sep 16, 2008 19:12
In article comcast.com>,
glen herrmannsfeldt ugcs.caltech.edu> writes:
> Steven G. Kargl wrote:
> (snip)
>
>> From FreeBSD /usr/include/errno.h,
>
>> #ifndef _KERNEL
>> #include
>> __BEGIN_DECLS
>> int * __error(void);
>> __END_DECLS
>> #define errno (* __error())
>> #endif
>
>> errno is not required to be an int variable.
>> It is required to be a modifable lvalue.
>
> In K&R2, the closest I have to a copy of the C89
> standard, errno is described as an expression. ...
|
| Show full article (1.55Kb) |
| no comments |
|
  |
Author: Arjen MarkusArjen Markus Date: Sep 16, 2008 23:37
On 16 sep, 17:06, glen herrmannsfeldt ugcs.caltech.edu> wrote:
> Arjen Markus wrote:
>
> (snip)
>
>> The easiest way to deal with errno, I'd say, is create a
>> small C function along these lines:
>
>> void get_errno( int &errno_value ) {
>> Â Â *errno_value = errno;
>> }
>
> or
>
> int get_errno() {
> Â Â Â return errno;
>
>
>
> }- Tekst uit oorspronkelijk bericht niet weergeven - ...
|
| Show full article (0.60Kb) |
| no comments |
|
  |
|
|
  |
Author: Arjen MarkusArjen Markus Date: Sep 16, 2008 23:38
On 17 sep, 08:37, Arjen Markus wrote:
> On 16 sep, 17:06, glen herrmannsfeldt ugcs.caltech.edu> wrote:
>
>
>
>
>
>> Arjen Markus wrote:
>
>> (snip)
>
>>> The easiest way to deal with errno, I'd say, is create a
>>> small C function along these lines:
>
>>> void get_errno( int &errno_value ) {
>>> Â Â *errno_value = errno;
>>> }
>
>> or
> ...
|
| Show full article (0.91Kb) |
| no comments |
|
|
|
|