-struct list
-{
- list* prev;
- list* next;
-};
-
-inline void list_init(list* h);
-inline list* list_head(list* h);
-inline list* list_tail(list* h);
-inline list* list_sentinel(list* h);
-inline list* list_next(list* n);
-inline list* list_prev(list* n);
-inline void list_del(list* n);
-inline int list_empty(list* h);
-inline void list_add_tail(list* h, list* n);
-inline void list_add_front(list* h, list* n);
+include "../lib/scf_list.c";
+include "../lib/scf_capi.c";
struct Data
{
int a;
};
-void* scf__malloc(uintptr_t size);
-int scf__free(void* p);
-int scf_printf(const char* fmt, ...);
-
int main()
{
Data* d;
list_init(&h);
- for (i = 0; i < 3; i++) {
- d = scf__malloc(sizeof(Data));
+ for (i = 0; i < 10; i++) {
+ d = malloc(sizeof(Data));
d->a = i;
list_add_tail(&h, &d->list);
d = container(l, Data, list);
l = list_next(l);
- scf_printf("%d\n", d->a);
+ printf("%d\n", d->a);
list_del(&d->list);
- scf__free(d);
+ free(d);
}
return 0;
}
-
+++ /dev/null
-
-struct scf_object_t
-{
- intptr_t refs;
- uintptr_t size;
-};
-
-int scf_printf(const char* fmt, ...);
-
-void scf__release_pt(void* objdata);
-
-void* scf__auto_malloc(uintptr_t size);
-
-void scf__auto_freep(void** pp, scf__release_pt* release);
-
-void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release);
-
-void scf__auto_free_array(void** pp, int size, int nb_pointers, scf__release_pt* release);
-
-void scf__auto_ref(void* data);
-
-
-int main()
-{
- int** pp = scf__auto_malloc(sizeof(int*) * 4);
-
- scf_printf("pp: %p\n\n", pp);
-
- int i;
- for (i = 0; i < 4; i++) {
- int* p = scf__auto_malloc(sizeof(int));
-
- pp[i] = p;
- scf_printf("\n");
- }
-
- return 0;
-}
-
+++ /dev/null
-
-int scf_printf(const char* fmt, ...);
-
-int main()
-{
- char buf[1024];
-
- float f = 2.71828;
- double d = -3.1415926;
- int64_t i64 = -255;
-
- int ret = scf_printf("i: %d, ld: %ld, x: %x, x: %#lx, p: %p, s: %s, f: %f, d: %lf\n",
- 100, i64, 254, 253, buf, "hello", f, -3.14);
-
- return ret;
-}
-
+++ /dev/null
-int scf_printf(const char* fmt, ...);
-
-int sort(int* a, int m, int n)
-{
- if (m >= n)
- return 0;
-
- int i = m;
- int j = n;
- int t;
-
- t = a[i];
- while (i < j) {
-
- while (i < j && t <= a[j])
- j--;
- a[i] = a[j];
- a[j] = t;
-
- while (i < j && a[i] <= t)
- i++;
- a[j] = a[i];
- a[i] = t;
- }
-
- sort(a, m, i - 1);
- sort(a, i + 1, n);
- return 0;
-}
-
-int main()
-{
- int a[10] = {11, 13, 15, 17, 19, 18, 16, 14, 12, 10};
-
- sort(a, 0, 9);
-
- int i;
- for (i = 0; i < 10; i++)
- scf_printf("%d\n", a[i]);
-
- return 0;
-}
+++ /dev/null
-
-#include<stdio.h>
-#include<stdint.h>
-#include<pthread.h>
-
-int64_t v = 0;
-
-void scf__atomic_inc(int64_t* p);
-void scf__atomic_dec(int64_t* p);
-int scf__atomic_dec_and_test(int64_t* p);
-
-void* thread(void* p)
-{
- int64_t *pi = p;
- int i;
- for (i = 0; i < 1000 * 1000; i++)
- scf__atomic_inc(p);
- return NULL;
-}
-
-int main()
-{
- scf__atomic_inc(&v);
- printf("v: %ld\n", v);
-
- scf__atomic_inc(&v);
- printf("v: %ld\n", v);
-
- scf__atomic_dec(&v);
- printf("v: %ld\n", v);
-
- int ret = scf__atomic_dec_and_test(&v);
- printf("v: %ld, ret: %d\n", v, ret);
-
- pthread_t tid;
- pthread_create(&tid, NULL, thread, &v);
-
- int i;
- for (i = 0; i < 1000 * 1000; i++)
- scf__atomic_inc(&v);
-
- pthread_join(tid, NULL);
-
- printf("v: %ld\n", v);
- return 0;
-}
intptr_t others;
};
-int scf__write(int fd, uint8_t* buf, uint64_t size);
-
int scf_ulong2a(char* buf, int* pn, int size, uint64_t num)
{
int n = *pn;
return ret;
}
+int main()
+{
+ char buf[1024];
+
+ float f = 2.71828;
+ double d = -3.1415926;
+ int64_t i64 = -255;
+
+ int ret = scf_printf("i: %d, ld: %ld, x: %x, x: %#lx, p: %p, s: %s, f: %f, d: %lf\n",
+ 100, i64, 254, 253, buf, "hello", f, -3.14);
+
+ return ret;
+}
+++ /dev/null
-
-int scf_printf(const char* fmt, ...);
-
-uintptr_t scf__strlen (const char *s);
-int scf__strcmp (const char *s1, const char *s2);
-int scf__strncmp(const char *s1, const char *s2, uintptr_t n);
-char* scf__strncpy(char *dst, const char *src, uintptr_t n);
-
-int main()
-{
- char buf[100];
- char* s0 = "hello1";
- char* s1 = "hello2";
-
- scf_printf("%s, len: %d\n", s0, scf__strlen(s0));
-
- scf_printf("%s, %s, cmp: %d\n", s0, s1, scf__strcmp(s0, s1));
- scf_printf("%s, %s, cmp: %d\n", s1, s0, scf__strcmp(s1, s0));
- scf_printf("%s, %s, cmp: %d\n", s0, s0, scf__strcmp(s0, s0));
-
- scf_printf("%s, %s, cmp: %d, n: %d\n", s0, s1, scf__strncmp(s0, s1, 5), 5);
-
- scf__strncpy(buf, s0, 5);
- scf_printf("buf: %s\n", buf);
-
- scf__strncpy(buf, s0, 6);
- scf_printf("buf: %s\n", buf);
-
- return 0;
-}
-
-
-void scf__release_pt (void* objdata);
-
-void* scf__auto_malloc(uintptr_t size);
-void scf__auto_ref(void* data);
-
-void scf__auto_freep (void** pp, scf__release_pt* release);
-void scf__auto_freep_array(void** pp, int nb_pointers, scf__release_pt* release);
-void scf__auto_free_array (void** pp, int size, int nb_pointers, scf__release_pt* release);
-
-uintptr_t strlen (const char *s);
-int strcmp (const char *s1, const char *s2);
-int strncmp(const char *s1, const char *s2, uintptr_t n);
-char* strncpy(char *dst, const char *src, uintptr_t n);
-int memcpy (void* dst, const void* src, uintptr_t n);
-int memcmp (void* dst, const void* src, uintptr_t n);
-
-int scf_printf(const char* fmt, ...);
-
+include "../lib/scf_capi.c";
struct string
{
s2 = s0 + s1;
s3 = "hello";
- scf_printf("### s0 == s3: %d, %s\n", s0 == s3, s0->data);
+ printf("### s0 == s3: %d, s0->data: %s, s2: %s\n", s0 == s3, s0->data, s2->data);
return 0;
}