Use another language to call a function: Difference between revisions
Content deleted Content added
m add link to Delphi for pascal |
|||
Line 85:
=={{header|C}}==
This is a restatement of the problem, it is not a solution. Please remove it.
<lang c>#include <stdio.h>
Line 105 ⟶ 106:
}
}</lang>
I rewrote the driver as
<lang c>#if 0
I rewrote the driver according to good sense, my style,
and discussion --Kernigh 15:45, 12 February 2011 (UTC).
This is file main.c on Autumn 2012 ubuntu linux release.
The emacs compile command output:
-*- mode: compilation; default-directory: "/tmp/" -*-
Compilation started at Mon Mar 12 20:25:27
make -k CFLAGS=-Wall main.o
cc -Wall -c -o main.o main.c
Compilation finished at Mon Mar 12 20:25:27
#endif
#include <stdio.h>
#include <stdlib.h>
extern int Query(char*Data,unsigned*Length);
int main(int argc,char*argv[]) {
char Buffer[1024], *pc;
unsigned Size = sizeof(Buffer);
if (!Query(Buffer,&Size))
fputs("failed to call Query",stdout);
else
for (pc = Buffer; Size--; ++pc)
putchar(*pc);
putchar('\n');
return EXIT_SUCCESS;
}
</lang>
With solution
<lang c>
#if 0
This is file query.c
-*- mode: compilation; default-directory: "/tmp/" -*-
Compilation started at Mon Mar 12 20:36:25
make -k CFLAGS=-Wall query.o
cc -Wall -c -o query.o query.c
Compilation finished at Mon Mar 12 20:36:26
#endif
#include<string.h>
int Query(char*Data,unsigned*Length) {
char*message = "Here am I";
unsigned n = strlen(message);
if (n <= *Length)
return strncpy(Data,message,(size_t)n), *Length = n, 1;
return 0;
}
</lang>
And finally, excitement!
<lang bash>$ gcc main.c query.o -o main && ./main
Here am I
$
</lang>
=={{header|Delphi}}==
|