chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] Embedded C Question


From: David N Murray
Subject: [Chicken-users] Embedded C Question
Date: Tue, 05 Jan 2010 11:31:52 -0500 (EST)

(apologies if this posts twice to the list.  originally sent 20 hours ago)

Hi all,

I've been toying around with embedded C just to learn how.  I have the
following sample:

(use easyffi)
(import foreign)

#>
#include <stdio.h>
#include <time.h>

const char* dummy(char* dst, int len, int seconds) {
  struct tm* tm = localtime(&seconds);
  snprintf(dst, len, "%02d/%02d:%02d:%02d:%02d:", tm->tm_mon + 1,
                   tm->tm_mday, tm->tm_hour,tm->tm_min, tm->tm_sec);
  return dst;
}
<#

(define c-dummy (foreign-lambda c-string "dummy" c-string
integer integer))

(define (test-dummy)
  (c-dummy (make-string 128) 128 1242403665))

(print (test-dummy))

It runs fine this way (actually, it also runs without the first two
lines):

$ csc t2.scm

Warning: re-importing already imported syntax: foreign-declare

Warning: re-importing already imported syntax: foreign-declare
/usr/local/lib/libchicken.so: warning: strcpy() is almost always misused,
please use strlcpy()
/usr/local/lib/libchicken.so: warning: sprintf() is often misused, please
use snprintf()
/usr/local/lib/libchicken.so: warning: strcat() is almost always misused,
please use strlcat()
$ ./t2
05/15:12:07:45:
$

However, when I try and run it in csi, I get the following:
$ csi t2.scm

CHICKEN
(c)2008-2009 The Chicken Team
(c)2000-2007 Felix L. Winkelmann
Version 4.3.0
openbsd-unix-gnu-x86-64 [ 64bit manyargs dload ptables ]
compiled 2010-01-04 on kili.jsbsystems.com (OpenBSD)

; loading ~/.csirc ...
; loading /usr/local/lib/chicken/4/readline.import.so ...
; loading /usr/local/lib/chicken/4/scheme.import.so ...
; loading /usr/local/lib/chicken/4/chicken.import.so ...
; loading /usr/local/lib/chicken/4/foreign.import.so ...
; loading /usr/local/lib/chicken/4/ports.import.so ...
; loading /usr/local/lib/chicken/4/data-structures.import.so ...
; loading /usr/local/lib/chicken/4/posix.import.so ...
; loading /usr/local/lib/chicken/4/readline.so ...
; loading t2.scm ...
; loading /usr/local/lib/chicken/4/easyffi.so ...
; loading /usr/local/lib/chicken/4/easyffi-base.so ...
; loading /usr/local/lib/chicken/4/easyffi.import.so ...

Warning: declarations are ignored in interpreted code: (##core#declare
(foreign-declare "\n#define _X_OPEN_SOURCE\n#include <stdio.h>\n#include
<time.h>\n\nconst char* bar2string(char* dst, int len, int seconds) {\n
struct tm* tm = localtime(&seconds);\n  snprintf(dst, len,
\"%02d/%02d:%02d:%02d:%02d:\", tm->tm_mon + 1, \n\t\t   tm->tm_mday,
tm->tm_hour,tm->tm_min, tm->tm_sec);\n  return dst;\n}\n" "\n"))

Error: unbound variable: foreign-lambda

        Call history:

        g626627
        action383
        <syntax>                (##core#declare (foreign-declare
"\n#define _X_OPEN_SOURCE\n#include <stdio.h>\n#include <time.h>\n\...
        <syntax>                (##core#undefined)
        <syntax>                (define c-bar2string (foreign-lambda
c-string "bar2string" c-string integer integer))
        <syntax>                (##core#set! c-bar2string (foreign-lambda
c-string "bar2string" c-string integer integer))
        <syntax>                (foreign-lambda c-string "bar2string"
c-string integer integer)
        <eval>          (foreign-lambda c-string "bar2string" c-string
integer integer) <--
$

What am I missing?

TIA,
Dave





reply via email to

[Prev in Thread] Current Thread [Next in Thread]