Entraides et échanges autour de la technologie Scol - Informations and exchanges on the Scol technology
Vous pouvez changer la langue de l'interface une fois inscrit - You can change the language once registered
You are not logged in.
Pages: 1
I'm digging in the vm, and i found something quite strange in "scolCbMachine.h":
struct CBmachine
{
...
int (*fread)(char* buf, size_t i, size_t j, FILE *f);
...
};
This function ptr is is latterly initialized as
int SCinitCBm(cbmachine w)
{
...
w->fread=fread;
...
}
The assignated "fread" being the standard c function declared in "stdio.h"... What's the point about that? Why declaring a standard C function as part of the VM, when it's always possible to call it directly?
At first I suspected a multithreading hack (to be sure that this function is called in scol thread), but it's non-sense too!
And as the std fread signature is not exactly the same as the one declared in size_t (originally, it's "size_t fread ( void * ptr, size_t size, size_t count, FILE * stream );"), it do not work for every buffers types, and can makes problems on systems where size_t is too big for int...
So, is there any reason to keep this horror? I will not remove it, just rename the (*fread) function ptr as it makes some conflicts in some cases with stdio definition...
But if anyone knows why this was done, i would like to know the reason
Last edited by Nodrev (30-May-2012 13:45:21)
Offline
Oh, Welcome to the club !
I searched several times on this ... thing. I know the source of 3.5 already contains this redefinition, so this dates from 1999/2000. I thinked too to skirt a specific problem in the VM. Or, anyone has thinked that the read data were chars, so he changed the prototype .... Unless it was an hideous hack to avoid a compilation warning or other thing.
In my mind, such a redefinition is not justified, fread is a C-standard function. If a speific prototype was imperative, a new function (like scolFread) was the best choice rather than a bullshit. I could be wrong Today, nobody knows why !...
Unless error on my part, this doesn't exist in the GNU/Linux version, the C-standard function is used.
Offline
Ok, thanks for the infos
Offline
Moreover, fread is the only classic file handling function which is re-defined in this way. So I do not think, at first glance, that handling fread in such a way is useful. I'll make a few tests to check this.
Offline
Thanks Bob, I already renamed it anyway .
Offline
Pages: 1