f



C library functions and _kernel_oserror

Dear All,

A lot of functions in the ANSI C library return values indicating
failure of some sort (e.g. if fwrite() returns that less than the
requested number of array elements were written), without being specific
about what the error was.

For some time I included a standard set of error messages in my
programs such as 'file write error', 'file read error', 'file open
error'. The trouble is that no matter how verbose you make these (e.g.
including the filename) they still aren't very meaningful to the user
- why WAS there a file write error?

Having read the following paragraph in the PRM chapter on the SCL...

"Some functions in the C library call _kernel functions, so if an C
library function (such as fopen("...", "r")) fails, try calling
_kernel_last_oserror to find out what the error was."

....I decided to modify all my applications to report any error returned
by _kernel_oserror by preference and fall back on built-in messages
where no OS error has been recorded.

My error handling now looks something like this:

int array[10];
FILE *handle;
....
_kernel_last_oserror(); /* reset SCL's error recording */
if(fwrite(array, sizeof(int), 10, handle) < 10) {
  if(_kernel_last_oserror() != NULL)
    fprintf(stderr, "%s\n", _kernel_last_oserror()->errmess);
  else
    fputs("Error writing to file\n", stderr);
}

Although this has the advantage that the user is informed 'disc full'
rather than the unhelpful 'Error writing to file', the code is rather
long winded - perhaps unnecessarily so.

Is it acceptable to assume _kernel_last_oserror() will always return a
meaningful and RELEVANT error message following an I/O failure? For
instance I believe the current C library has a limit of 8 file handles -
presumably exceeding this limit would be an fopen() failure for which
there would be no corresponding OS error! Thus I have been forced to
keep my original message as a fallback.

The above approach also has the disadvantage of being non-portable.
Would _kernel_last_oserror() also return a relevant message under
Unixlib, for instance?

For many RISC OS applications the lack of portability is a non-issue,
but then why not simply use the native "kernel.c" functions
such as_kernel_osfile? These are *guaranteed* to cooperate nicely with
_kernel_last_oserror(), which would overall produce a considerable
saving in code size. For example, the program above would reduce to:

_kernel_osgbpb_block inout;
inout.dataptr = array;
inout.nbytes = sizeof(int)*10;
if(_kernel_osgbpb(2, handle, &inout) == _kernel_ERROR)
  fprintf(stderr, "%s\n", _kernel_last_oserror()->errmess);

How do other people do error handling in C - any tips? Would it be
better to go for either the 'pure' ANSI method or the RISC OS specific
method, rather than attempting to mix the two?

Cheers,
-- 
Chris Bazley
===================================================================
My corner of the web: http://www.bigfoot.com/~chrisbazley/
Star Fighter 3000 web home: http://www.starfighter.acornarcade.com/
0
chrisbazley (205)
7/7/2003 2:26:08 PM
comp.sys.acorn.programmer 2499 articles. 0 followers. Post Follow

8 Replies
336 Views

Similar Articles

[PageSpeed] 59

In <1896500e4c.chris@freeuk.com>,
Christopher Bazley <chrisbazley@bigfoot.com> wrote:

> _kernel_last_oserror(); /* reset SCL's error recording */
> if(fwrite(array, sizeof(int), 10, handle) < 10) {
>   if(_kernel_last_oserror() != NULL)
>     fprintf(stderr, "%s\n", _kernel_last_oserror()->errmess);
>   else
>     fputs("Error writing to file\n", stderr);
>}

I haven't got kernel.h to hand ATM so I can't check, but if calling
_kernel_last_oserror() resets the condtion, isn't the above code wrong?
The if statement would reset it so you'd be trying to report a NULL
error.

> Although this has the advantage that the user is informed 'disc full'
> rather than the unhelpful 'Error writing to file', the code is rather
> long winded - perhaps unnecessarily so.

[Snip]

> The above approach also has the disadvantage of being non-portable.
> Would _kernel_last_oserror() also return a relevant message under
> Unixlib, for instance?

I'd wrap it up in functions and/or macros. It's quite common to use
the preprocessor to help with portability eg

#ifdef __riscos
#define RESET_SYS_ERROR() _kernel_last_oserror()
#else
#define RESET_SYS_ERROR() (errno = 0)
#endif

extern void report_sys_error(const char *message, ...);
/* Uses perror() or _kernel_last_oserror() depending on system */

Or you might find using errno and strerror or perror is just as
effective in RISC OS as anywhere else and you don't need
_kernel_last_oserror().

I used variable arguments because they're always useful when reporting
errors etc. There's nearly always some extra information you can add to
give your errors more context, in this case the filename.

You can also use macros to report extra things like __FUNCTION__,
__FILE__ and __LINE__ to get you straight to the problem when debugging.

-- 
Use Reply-To and DO NOT remove .nospam when replying
0
Tony
7/7/2003 11:08:42 PM
On Mon, 7 Jul 2003, Christopher Bazley wrote:

> Dear All,
>
[snip]
>
> My error handling now looks something like this:
>
> int array[10];
> FILE *handle;
> ...
> _kernel_last_oserror(); /* reset SCL's error recording */
> if(fwrite(array, sizeof(int), 10, handle) < 10) {
>   if(_kernel_last_oserror() != NULL)

This reads and then clears the error.

>     fprintf(stderr, "%s\n", _kernel_last_oserror()->errmess);

This tries to print out address 0+4 which starts with a NUL, so you'll get
nothing printed. So either there's some magic that is happening that I'm
missing or the code you've written isn't 'something like' what you've got.

>   else
>     fputs("Error writing to file\n", stderr);
> }

-- 
Gerph {djf0-.3w6e2w2.226,6q6w2q2,2.3,2m4}
URL: http://www.movspclr.co.uk/
.... The streets are lonely and the doorways they only cover the dead.
0
7/8/2003 12:22:06 AM
Christopher Bazley wrote:

>Would _kernel_last_oserror() also return a relevant message under
>Unixlib, for instance?
>  
>
Yes (or it is at least the purpose).

John.

0
this (338)
7/8/2003 10:04:57 AM
In message <slrnbgjvbq.9s4.{tony}@realh.co.uk>
          Tony Houghton <{tony}@realh.co.uk> wrote:

> In <1896500e4c.chris@freeuk.com>,
> Christopher Bazley <chrisbazley@bigfoot.com> wrote:
> 
> > _kernel_last_oserror(); /* reset SCL's error recording */
> > if(fwrite(array, sizeof(int), 10, handle) < 10) {
> >   if(_kernel_last_oserror() != NULL)
> >     fprintf(stderr, "%s\n", _kernel_last_oserror()->errmess);
> >   else
> >     fputs("Error writing to file\n", stderr);
> >}
> 
> I haven't got kernel.h to hand ATM so I can't check, but if calling
> _kernel_last_oserror() resets the condtion, isn't the above code wrong?
> The if statement would reset it so you'd be trying to report a NULL
> error.

You're quite right - that'll teach me to type in programs off the
top of my head without checking them properly! Fortunately my actual
code doesn't contain this error. Of course the correct way to do it is
as follows:

_kernel_last_oserror(); /* reset SCL's error recording */
if(fwrite(array, sizeof(int), 10, handle) < 10) {
  _kernel_oserror *e = _kernel_last_oserror();
  if(e != NULL)
    fprintf(stderr, "%s\n", e->errmess);
  else
    fputs("Error writing to file\n", stderr);
}

[snip]

> > The above approach also has the disadvantage of being non-portable.
> > Would _kernel_last_oserror() also return a relevant message under
> > Unixlib, for instance?
> 
> I'd wrap it up in functions and/or macros. It's quite common to use
> the preprocessor to help with portability eg
> 
> #ifdef __riscos
> #define RESET_SYS_ERROR() _kernel_last_oserror()
> #else
> #define RESET_SYS_ERROR() (errno = 0)
> #endif

It is usual to zero errno before calling a library function for which you
are expecting to do error checking? I /think/ that the necessity of this is
implied by the following paragraph (from Acorn's <errno.h>)...

"The value of errno may be set to nonzero by a library function call
whether or not there is an error, provided the use of errno is not
documented in the description of the function in the Standard."

....though this is not very clear. Why should a function set errno
without good reason?

> extern void report_sys_error(const char *message, ...);
> /* Uses perror() or _kernel_last_oserror() depending on system */
> 
> Or you might find using errno and strerror or perror is just as
> effective in RISC OS as anywhere else and you don't need
> _kernel_last_oserror().

I must admit that I have never investigated the ANSI C library's errno,
perror() and strerror() because they always appeared to me to be
unbelievably primative and on the whole not very useful: In the
<errno.h> supplied with Acorn's DDE only three non-0 values of errno are
defined - EDOM, ERANGE and ESIGNUM. Surely these will be very rarely (if
ever) used?

(A quick glance at UnixLib's <errno.h> reveals that it defines a vast
number of meaningful values for errno. Is this usual for C libraries on
other operating systems? Perhaps it is only Acorn's implementation that is
lacking.)

For file I/O, where runtime errors can be expected to occur, there
are (according to K&R 2nd ed.) no ANSI defined error numbers at all!
Because of this, and the fact that so few of the <stdio.h> functions are
documented as setting errno, it had never even occured to me that
perror() would be a sensible response to - for example - a NULL pointer
returned by fopen().

I was therefore surprised to find that fopen() DOES set errno, despite
not being documented as doing so. Under the RISC OS Shared C Library,
attempting to open a non-existent file will set errno to -1 and
perror() will output the OS error message "File 'foo' not found".
Presumably -1 is a 'magic' value, since strerror(-1) on it's own doesn't
yield anything useful.

Sadly, it seems that you cannot rely on <stdio.h> functions setting
errno for failure conditions. For example attempting to fopen() too
many files (this should be FOPEN_MAX+1, but the SCL will actually allow
me to open 13) will result in the unhelpful message "No error (errno =
0)" from perror(). Experimentation suggests that errno is also 0 after
attempting to fread() more data from a file than is present.

All of which serves to put me off the ANSI C library's native error
handling once again. :(

-- 
Chris Bazley
===================================================================
My corner of the web: http://www.bigfoot.com/~chrisbazley/
Star Fighter 3000 web home: http://www.starfighter.acornarcade.com/
0
chrisbazley (205)
7/8/2003 12:50:24 PM
In message <Pine.LNX.4.55.0307080116180.12524@buttercup>
          Justin Fletcher <justin.fletcher@ntlworld.com> wrote:

> On Mon, 7 Jul 2003, Christopher Bazley wrote:
> 
> > Dear All,
> >
> [snip]
> >
> > My error handling now looks something like this:
> >
> > int array[10];
> > FILE *handle;
> > ...
> > _kernel_last_oserror(); /* reset SCL's error recording */
> > if(fwrite(array, sizeof(int), 10, handle) < 10) {
> >   if(_kernel_last_oserror() != NULL)
> 
> This reads and then clears the error.
> 
> >     fprintf(stderr, "%s\n", _kernel_last_oserror()->errmess);
> 
> This tries to print out address 0+4 which starts with a NUL, so you'll get
> nothing printed. So either there's some magic that is happening that I'm
> missing or the code you've written isn't 'something like' what you've got.

Yes it is 'something like', no it isn't actual code copied verbatim.
See my follow-up to TH's posting.

-- 
Chris Bazley
===================================================================
My corner of the web: http://www.bigfoot.com/~chrisbazley/
Star Fighter 3000 web home: http://www.starfighter.acornarcade.com/
0
chrisbazley (205)
7/8/2003 5:31:25 PM
Christopher Bazley <chrisbazley@bigfoot.com> wrote:

> It is usual to zero errno before calling a library function for which you
> are expecting to do error checking? I /think/ that the necessity of this
> is implied by the following paragraph (from Acorn's <errno.h>)...
> 
> "The value of errno may be set to nonzero by a library function call
> whether or not there is an error, provided the use of errno is not
> documented in the description of the function in the Standard."
> 
> ...though this is not very clear. Why should a function set errno
> without good reason?

The standard will tell you that library will NEVER set errno to zero.  I
don't have the reference to hand, but trust me - it does say it.  Therefore,
provided you set errno to zero before calling a library function, you can
tell whether or not the library function has set errno when it returns an
error condition.  If it's zero, then it has not set it; if it is non-zero,
then that's the error.

It may be the case that some calls want to succeed, but in some manner
indicate a problem occurred.  To use your later example of fread, it is
possible that despite successfully reading a number of items from the file,
some failure was detected which prevented completion of the request.

> I must admit that I have never investigated the ANSI C library's errno,
> perror() and strerror() because they always appeared to me to be
> unbelievably primative and on the whole not very useful: In the
> <errno.h> supplied with Acorn's DDE only three non-0 values of errno are
> defined - EDOM, ERANGE and ESIGNUM. Surely these will be very rarely (if
> ever) used?

> (A quick glance at UnixLib's <errno.h> reveals that it defines a vast
> number of meaningful values for errno. Is this usual for C libraries on
> other operating systems? Perhaps it is only Acorn's implementation that is
> lacking.)

That's all you need for a standard *C* library.  errno.h is a C library
header.  It need only define C library implementation error codes.

The TCP/IP libraries have a more comprehensive list - and these are based on
the values of errno returned by UNIX system calls and C libraries.  For
example, a file not found can be represented with errno = ENOENT.


> For file I/O, where runtime errors can be expected to occur, there
> are (according to K&R 2nd ed.) no ANSI defined error numbers at all!
> Because of this, and the fact that so few of the <stdio.h> functions are
> documented as setting errno, it had never even occured to me that
> perror() would be a sensible response to - for example - a NULL pointer
> returned by fopen().

And it doesn't reliably do so under RISC OS until very recent versions of
the C library.

The standard says that if errno usage is not specifically mentioned for any
given library function, then the implementation can do what it likes, or
something like that.

> I was therefore surprised to find that fopen() DOES set errno, despite
> not being documented as doing so. Under the RISC OS Shared C Library,
> attempting to open a non-existent file will set errno to -1 and
> perror() will output the OS error message "File 'foo' not found".
> Presumably -1 is a 'magic' value, since strerror(-1) on it's own doesn't
> yield anything useful.

I think there is some trickery going on and that -1 means to look in the
static kernel error message buffer in the stubs data area.  BICBW - I've not
looked at this for a few years, but it sounds plausible.

> Sadly, it seems that you cannot rely on <stdio.h> functions setting
> errno for failure conditions. For example attempting to fopen() too
> many files (this should be FOPEN_MAX+1, but the SCL will actually allow
> me to open 13) will result in the unhelpful message "No error (errno =
> 0)" from perror().

Isn't FOPEN_MAX is the *minimum* number of files that are guaranteed to be
openable at the same time for a portable implementation (which is 8, IIRC)?
You actually get 16 with the SharedCLibrary, although the first three are
pre-allocated for stdin, stdout & stderr.  You can close these streams and
reuse them.


> Experimentation suggests that errno is also 0 after
> attempting to fread() more data from a file than is present.

But fread will not have returned you an error (returned -1) - therefore you
have no right to expect errno to be set.  fread will tell you how many
things of the size you specified that it managed to read completely.


-- 
Stewart Brodie
0
7/8/2003 11:06:37 PM
Hi Christopher,

I wrote:
> Well, fread() isn't defined to set errno so you perror() just in case
> it's something useful, but it may not be.

Note, in this case you do have to set errno to zero before making the
library call else perror() may show some older error.  Given errno isn't
in fread()'s interface, I'd not use perror:

    foo: error: read only 4 52 byte items from /tmp/bar instead of 10.

Cheers,

-- 
Ralph Corderoy.      http://inputplus.co.uk/ralph/     http://troff.org/
0
ralph6281 (150)
7/10/2003 10:33:47 AM
In message <3F0A9749.7060801@is.invalid>
          John Tytgat <this@is.invalid> wrote:

> Christopher Bazley wrote:
> 
> >Would _kernel_last_oserror() also return a relevant message under
> >Unixlib, for instance?
> >  
> >
> Yes (or it is at least the purpose).
> 
> John.
 
Hmm... I'm not so sure. Looking at the unixlib source code for fopen()
it doesn't actually appear to use the _kernel_osfind() function
internally, as the Shared C Library is documented as doing. Instead it
uses a separate veneer onto OS_Find called __os_fopen().

AFAICT it is only the SCL compatability functions themselves that call
__seterr() to store an OS error for subsequent retrieval using
_kernel_last_oserror(). So if the stdio functions aren't using the SCL
functions then I wouldn't expect _kernel_last_oserror() to return any OS
error that might occur.

-- 
Chris Bazley
===================================================================
My corner of the web: http://www.bigfoot.com/~chrisbazley/
Star Fighter 3000 web home: http://www.starfighter.acornarcade.com/
0
chrisbazley (205)
7/12/2003 12:12:51 PM
Reply:

Similar Artilces:

Internal of C/C++ run time library (Module offers a function that allocates memory, must also offer a function that frees memory)??
Single address space consists of one executable module and several DLL modules. Some of these modules can link to a static version of the C/C + + run-time library, some of these modules might link to a DLL version of the C/C++ run-time library, and some of these modules (if not written in C/C++) might not require the C/C++ run-time library at all. Please put some light on how C/C++ runtime library malloc or free functions works in a address space and how static linking or dynamic linking can affect the allocation or deallocation of a memory in a single address space. Thanks in a...

function work only once (C library / c# application)
I have Matlab code compiled into C library. I am using this library from C# application. If I call my function in C library for the first time, everything works fine, but the second call causes an exception - mlfMyfunc returns null pointer insted pointer to results (output1 and output2 parameters are IntPtr.Zero even after mlfMyfunc call) My DoubleArray class (wrapper around mx.... functions), it is well tested and I think it works correctly. Do you have any idea where problem could be? Thanks. Lukas C# code: using Native; class MatlabAlgosBridge { [DllImport("Algos.dll"] pri...

Calling third party C library functions from C++
Hello All, I have searched internet and also posts on this group. None of the suggestions have worked in my case. I am having linker issues when I try to use a C funtion in C++ code. Though I have declared that C function as extern "C" c_func(......) in my .cpp file. Also this c_func takes argument as (void*, void (cpp_func*)(int, void*, unsigned long), void*) Here cpp_func is a pointer to a function in my .cpp file(not a member function) where I am calling this c_func To avoid name mangling by C++ compiler for the function to which cpp_func points to I have also declared this...

Beware of bug in flex library with Acorn C/C++
Hello folks, I've just run up against what I'm pretty certain is a bug in the Flex memory library supplied with Acorn C/C++. I thought I'd let others know about it so that they aren't as puzzled as I was when it manifested (on my machine an error box pops up saying simply 'Message token', then my application quits). The problem seems to be that when trying to report a 'flex1'-type error, the code gets the parameters to SWI MessageTrans_ErrorLookup wrong. My attempt at a disassembly of the offending function follows: fatal_lookup ; Arguments - a1 pointer to error block with message token ; a2 pointer to error block with default message MOV ip,sp STMDB sp!,{v1,fp,ip,lr,pc} SUB fp,ip,#4 LDR v1,addr_flex_initialised LDR a3,[v1,#8] ; 'error_fd' passed to flex_init CMP a3,#0 ; use English default messages? BEQ no_message_file ; yes ; a3 (R1 for SWI) should be pointer to error block! MOV a4,#0 STR a4,[sp,#-4]! ; push argument onto stack MOV a4,a1 ; pointer to error block with message token ; a4 (R2 for SWI) should be pointer to message file descriptor! MOV a2,#7 ; _INR(0,2) LDR a1,MessageTrans_ErrorLookup ; get SWI number from literal pool BL _swix ADD sp,sp,#4 MOV a3,a1 B report_wimp_error addr_flex_initialised DCD flex_initialised MessageTrans_ErrorLookup DCD &41506 ; MessageTrans_ErrorLookup no_message_file MOV a...

how to monitor network status using C/C++ library functions
I want to constantly monitor my own network status in a program. This can be done using netstat command. But is there any command in the C/C++ library which can be used for the same purpose. Another option is to execute the netstat command in the program, but is it advisable to run a command continuously in a progam (as i want to monitor my status continuously). What will be the effect of of doing so on the memory usage and cpu load ?? Sumir wrote: > I want to constantly monitor my own network status in a program. This > can be done using netstat command. But is there any command in the > C/C++ library which can be used for the same purpose. Another option is > to execute the netstat command in the program, but is it advisable to > run a command continuously in a progam (as i want to monitor my status > continuously). What will be the effect of of doing so on the memory > usage and cpu load ?? > Well, you can always look at the source for netstat and do what netstat does; that will save you the overhead of running netstat and possibly a shell. Robert ...

Manual for Acorn Desktop C (repost from c.s.a.programmer)
I've got one set of manuals - well I had the discs as well, but have disposed of them - for Acorn ANSI C release 4. I'm about to dispose of the manuals as well; unless somebody has a use for them. I'm after =A310 to cover carriage and handling. If nobody replies before 1pm, i'll be disposing of them via the trash... Dave ...

c++ library functions
I am attempting to compile a package using gcc 4.3.2 Due to the changes in gcc the package fails to compile. Where can I get a list of the various functions in c++ and which header file they are in? I am looking for strcasecmp My man files tell me that it is in <string.h> whick is for c but I need the header file for cpp Thank you Gang Greene wrote: > I am looking for strcasecmp > > My man files tell me that it is in <string.h> whick is for c but I need > the header file for cpp You should be able to use any C header from C++, too. Uli ...

error using mcc, "Function 'findobj' requires C/C++ graphics library
Hi all, I have written a MATLAB program using fmincon to optimize an objective function with non-linear constraints. However, for some initial guesses of the design variables, fmincon produces values outside the lower and upper limits that I specified for the variables and freezes because outside these limits, my objective function and constraints become imaginary. To overcome this, as someone in this group suggested a few days ago, I used lsqnonlin to obtain a good initial guess and then run fmincon using this guess. This is running fine from the MATLAB prompt. Now, I used "mcc -m fi...

Is the average IQ of C programmers less than that of C++ programmers?
I have a feeling that their EQ will show to be significantly lower. Feel free to post your IQs and EQs! On Tuesday, March 29, 2011 5:19:46 AM UTC+1, MikeP wrote: > I have a feeling that their EQ will show to be significantly lower. Feel > free to post your IQs and EQs! That would make C a better language for commercial purposes, wouldn't it? When I worked as a programmer, the management attitude was that they didn't want clever code; they wanted code that other staff could maintain and develop as easily as its author, especially after he had gone. On that basis, the lowest-IQ language would be the best of all! -- In message <ae3c092a-4fa2-4d9f-8a26-9665e18b98b6@glegroupsg2000goo.googl egroups.com>, bert <bert.hutchings@btinternet.com> writes >On Tuesday, March 29, 2011 5:19:46 AM UTC+1, MikeP wrote: >> I have a feeling that their EQ will show to be significantly lower. Feel >> free to post your IQs and EQs! > >That would make C a better language for commercial purposes, >wouldn't it? When I worked as a programmer, the management >attitude was that they didn't want clever code; they wanted >code that other staff could maintain and develop as easily >as its author, especially after he had gone. On that basis, >the lowest-IQ language would be the best of all! I couldn't agree more! Clever code is usually an oxymoron. BTW That is why English is the most common language on the planet as ...

call library function node: function not found in library
I'm using Labview 6.1 and Windows XP.&nbsp; I am trying to&nbsp;open some code, but it opens up with a broken arrow.&nbsp; The error is Call Library Function Node:function not found in library.&nbsp; Tried to configure the node, but no change.&nbsp; Moved the DLLs to various directories (keeping them together) but again no change.&nbsp; &nbsp; This code has been compiled and is working fine.&nbsp; I'm just trying to run the source code to&nbsp;make some modifications.&nbsp; Any suggestions?&nbsp; &nbsp; Thanks &nbsp; CarlosV Hi Carlos, Is this a custom DLL, or&nbsp;is it possible there's an old copy of the DLL that's getting loaded?&nbsp; To simplify diagnosis, I'd close LabVIEW, locate/remove any redundant copies, then reload the calling VIs. What happens when you browse the available functions in the "Call Library Function" dialog - does the Function Name&nbsp;appear in the pull-down menu? Cheers. Thanks for the suggestions.&nbsp; Tried it but had the same results.&nbsp; The library I'm using is hpe1413_32.dll.&nbsp; &nbsp; One thing I forgot to mention....doing a configure on the node, it comes up with the library: hpvscp32.dll and the function: hpe1413_error_message &nbsp; The function doesn't exist in the library.&nbsp; So I set the path to hpe1413_32.dll which does contain the function.&nbsp; &nbsp; After closing the configuration w...

Invoking c function in a c plus plus function...
Hi Everyone, I want to invoke a c function ( object file created by cc ) from a cpp function ( object file is created using g++ ). When i try to link, both the object files using g++ g++ cfile.o cppfile.o i get an error saying, : undefined reference to `fun()' collect2: ld returned 1 exit status Note that the fun() is the c function defined in cfile.c. I can't use cc to link both the object files as the master file is a cpp source file. Is there anyway to get this done? I know the method of using extern "C" but that works only when a cpp function ( object file cre...

How to write a C wrapper dll to export Matlab dll functions so that LabVIEW Call Library Function Node can use it?
Hello LabView developers, &nbsp; I used LabVIEW to call Matlab m script to implement matlab MPC successfully. I wanted to use Matlab compiler to compile the matlab m script function into a c&nbsp;shared library&nbsp;.dll so that LabVIEW can call it without requiring Matlab installed on the PC. &nbsp; I used MatLab R2007b with matlab compiler. I was able to generate a C shared library dll set successfully using mcc command. &nbsp; However, from the header file, I see that the inputs and outputs of&nbsp;the function prototype&nbsp;are&nbsp;in mxArray. I need to change this data type to whatever that&nbsp;LabView Call&nbsp;Library Function Node can recognize. &nbsp; I have followed a few examples in the forum, but none of them went through. &nbsp; I use LabView 8.5. I have Microsoft Visual C++ Version 6 and Microsoft Visual Studio 2005. The compiler is in C++. Should I use a C compiler only to generate the C wrapper dll so that Labview can recognize it in the Call Library Function Node? &nbsp; If anybody has gone through this successfully, I would like to learn from you on how to do it. &nbsp; Thanks, &nbsp; Kimberly yw wrote: Hello LabView developers, &nbsp; I used LabVIEW to call Matlab m script to implement matlab MPC successfully. I wanted to use Matlab compiler to compile the matlab m script function into a c&nbsp;shared library&nbsp;.dll so that LabVIEW can call it without requiring Matlab installed ...

C++ for C programmer
I know C, and i want to learn c++. can someone recommend an on-line source? - I also already know javascript. will that help? Thanks. ~M ---- http://www.NovelTracker.com - top ten novels, ranked hourly. On Mar 13, 10:08 am, marywilliams1...@yahoo.com wrote: > I know C, and i want to learn c++. can someone recommend an on-line > source? - I also already know javascript. will that help? See the FAQ: http://www.parashift.com/c++-faq-lite/how-to-learn-cpp.html I'd suggest you get _Accelerated C++_ by Koenig and Moo. It will teach you the right way from the ground up (and ...

F77-C: Passing Fortran FUNCTION as an argument for a C Function
Hello, I have a Fortran FUNCTION f1, a Fortran SUBROUTINE s1 and a C function c1. c1 has following prototype: void c1(double *,double (*fkt)(double,double*)); Now i want to CALL c1 from s1 and pass f1 as the second argument for c1. Is it possible? If yes, then how should i define c1 interface in Fortran? And how do i call c1 then? tia, schamil Schamil Wackenhut wrote: > Hello, > > I have a Fortran FUNCTION f1, a Fortran SUBROUTINE s1 and a C function > c1. > > c1 has following prototype: > > void c1(double *,double (*fkt)(double,double*)); > > Now i wa...

Calling Lisp Function from C: How to declare this function in C land ?
Hi all: I have a lisp image that contains the following functions: (defun frgo (a) (format *debug-io* "~%~A~&" a) (values)) (cffi:defcallback frgo_helper :void ((a-cstr :string)) (frgo (cffi:foreign-string-to-lisp a-cstr))) In a C dynamic library I have: * file frgo_c.h: extern void frgo_helper( char * a ); * file frgo_c.c: void frgo( char * a ) { frgo_helper( a ); } Now, the library does not compile - undefined symbol _frgo_helper() ! How do I make functions "known" to C land that are purely defined as callbacks in Lisp land? I tried to declare the function in C land like this: extern void frgo_helper( char * a ) __attribute__((weak_import)); No luck, though. My environment is: Mac OS X Snow Leopard (10.6.8), Apple LLVM compiler 3.0. An ideas / hints / tipps? Thanks a lot! Cheers Frank ...

Libraries for C S-functions
I am new to the world of Simulink. I have used Matlab for over 5 years now. I am trying to implement a complicated operation using C Mex S-functions. Are there libraries available to some common Matrix operations in C Mex? ...

matlab function as c library
Hi, So I am writing some code in C (it has to be in C because I am programming a microcontroller) and I want to use the matlab function of the Levenberg Marquardt curve fitting technique in my C code. Is there a way to export it from matlab and into a library that my C program can use standalone from Matlab? I have an array of data, and an equation that I will use to fit the data to. Please can someone help me with this. Alex ...

Problem with linking C shared library into C++ shared library
Hello! A Corba Components server uses Components as shared libraries that are loaded into the server at runtime. Everything is C++ but I wrote a component which uses libmpeg2 for video decoding and displaying. I use "extern C" to use the mpeg2 C code inside the C++ component. The component shared library compiles and links ok, but when I try to load it into the server I get a "cannot load shared library; undefined symbol" error, for all symbols from libmpeg2. The mpeg2 libraries are all linked and it should work: I tried a simple executable with mpeg2, the c...

How to impliment searching the definition of a c/c++ function in a c/c++ source file
How to impliment searching the definition of a c/c++ function in a c/c+ + source file? are there any libs of opensource to use? I have no ideal about it, and any one who responses it will be appreciated. -- [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ] On Jun 18, 5:25 am, whiteid...@gmail.com wrote: > How to impliment searching the definition of a c/c++ function in a c/c+ > + source file? are there any libs of opensource to use? I have no > ideal about it, and any one who responses it will be a...

How can I convert a matlab function to C/C++ callable dll function ?
Dear Community Members I'd like to convert my .m file function to a C/C++ callable dll function. How can I convert an m file function to a C/C++ callable dll function and How can I call and parse it inside a C/C++ function ? Yours Faithfully Cem DEMiRKIR ...

How to declare a C or C++ function in a Objective C class
Hi, I need to write few functions, which I need to pass to a method in Objective C class using the pointers to those functions. These functions use the instance variable of the class. Hence they must have access to the variables. I want to write functions in C or C++ because they are crucial to the efficiency of my code and I don't want to use selectors way of passing methods for the same reasons. Then where do I include the function declations and implementations in ..h and .mm files of the class. Ankush In article <1150755755.068251.207990@h76g2000cwa.googlegroups.com>, ankushiitk@gmail.com wrote: > Hi, > I need to write few functions, which I need to pass to a method in > Objective C class using the pointers to those functions. These > functions use the instance variable of the class. Hence they must have > access to the variables. > I want to write functions in C or C++ because they are crucial to the > efficiency of my code and I don't want to use selectors way of passing > methods for the same reasons. > Then where do I include the function declations and implementations in > .h and .mm files of the class. > Ankush Consider adding a userData parameter to your fast C++ functions. Define a struct that has a pointer to your Objective C object instance members. Add an initBridge Objective-C method that initializes the struct with pointers to objective-C members. Now, your fast function ...

[Simulink, S-functions] Calling Lapack++ library from a library called by a S-function
Hello fellow Simulink users, I am developing some C++ S-functions which call an external C++ library for physical computations. Library exports match the principal methods used by the runtime environment : (excerpt from the library header file :) __declspec( dllexport ) static MyPhisicalBlock* create( void ) ; __declspec( dllexport ) void set_parameters( double* foo, double* bar ) ; __declspec( dllexport ) void outputs( const double* const in1, double* out1, double* out2r ) ; __declspec( dllexport ) void derivatives( c...

Writing C MEX S-Function from existing Matlab C MEX function
I have an existing Matlab C MEX function (walkode.dll) that returns state derivatives when called by ode23s (walkode,...) from a regular Matlab script or the command line. I would like to incorporate this into a Simulink model, and have done so using a Level 1 M-file S-function, which called walkode in the mdlDerivatives subfunction. However this model runs very slowly. I would prefer to rewrite (recompile?) my .dll as a C MEX S- function (using sfuntmpl_doc.c I believe), but I am unsure as how to go about doing so. This is where my understanding (or more aptly, misunderstanding) of C,...

regarding free function in c library
Hi Everyone, It is known that function free() of c library expects parameter of type void* and when we invoke them with pointers to any type, compiler automatically performs the typecast, can anyone let me know as to why pointers are typecasted to void* in many places before performing operation on them? sam_cit@yahoo.co.in wrote: > Hi Everyone, > > It is known that function free() of c library expects parameter of > type void* and when we invoke them with pointers to any type, compiler > automatically performs the typecast, can anyone let me know as to why > pointers...

Web resources about - C library functions and _kernel_oserror - comp.sys.acorn.programmer

Resources last updated: 3/25/2016 11:41:21 AM