Is there is a way to write to txt file from an e (hardware language) code and then to write to the same file from a C code ?
-
3What is an `e code`? C is a well known language, you don't need to explain that, but `e` is not obvious to most of us. – abelenky Feb 03 '15 at 15:31
-
Probably this [hipster language](http://en.wikipedia.org/wiki/E_%28programming_language%29) – dmg Feb 03 '15 at 15:32
-
e is a C based language for HW – user1941008 Feb 03 '15 at 15:33
-
@user1941008 Oh, you mean this [other strange language](http://en.wikipedia.org/wiki/E_%28verification_language%29) – dmg Feb 03 '15 at 15:35
-
@abelenky: Click on the "e" tag and read the tag wiki. – Keith Thompson Feb 03 '15 at 15:45
-
e-tag: "19 followers, 28 questions"... not enough to give me confidence, esp. since @dmg immediately dug up two different meanings for `e`. The burden is on OP to ask a clear question, not on respondents. – abelenky Feb 03 '15 at 15:47
-
2@abelenky There are actually two more that often go by the name **E** - [GNU E](http://en.wikipedia.org/wiki/GNU_E) and [Amiga E](http://en.wikipedia.org/wiki/Amiga_E). And that is just fast scraping wikipedia :D – dmg Feb 03 '15 at 15:50
2 Answers
In general, access to files is controlled by the Operating System.
Any number of programs, running on any number of separate processes can access the same file if they use the locking & synchronization methods provided by the Operating System.
This will typically involve opening the file in a Shared or Exclusive mode, opening it for Reading, Writing or both, and setting buffering options. It may also involve sharing a lock-mechanism, such as a mutex, between different programs.

- 63,815
- 23
- 109
- 159
You can have C code like following:
static FILE *f = NULL;
void cwrite() {
if (f == NULL)
f = fopen("ec.txt", "a");
fprintf(f, "print from C\n");
}
And then use it from e together with e write:
routine cwrite();
extend sys {
!f: file;
run() is also {
f = files.open("ec.txt", "a", "Text file");
for i from 0 to 100 {
files.write(f, "print from e");
cwrite();
};
};
};
However, the tricky part is that on linux level, fopen in C and files.open in e create separate file descriptors for exactly the same file, and this can lead to very weird result.
To make it synced, you should either keep your file closed when not writing (which might mean unneeded performance overhead), or really write only from one language, and when you need to write from another - send it as a string to the one that actually does that, you only need to define some simple API for that.

- 338
- 1
- 4