Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!uunet!proto!joe From: joe@proto.com (Joe Huffman) Newsgroups: comp.std.c Subject: Re: ANSI C standard library Message-ID: <1991May01.191956.18264@proto.com> Date: 1 May 91 19:19:56 GMT References: <1991Apr20.092845.14164@watdragon.waterloo.edu> <681@taumet.com> <307@nazgul.UUCP> <16014@smoke.brl.mil> Organization: Prototronics @ Sandpoint, Idaho Lines: 60 gwyn@smoke.brl.mil (Doug Gwyn) writes: >In article <307@nazgul.UUCP> bright@nazgul.UUCP (Walter Bright) writes: >-In article <681@taumet.com> steve@taumet.com (Stephen Clamage) writes: >-/Can you name any other functions in the standard C library which >-/cannot reasonably be written in strictly-conforming C. [...list deleted...] >With the possible exception of the startup code, all the above can >be reasonably written in strictly-conforming C in most environments. Huh? You have me a bit confused. I did the port of Zortech to SCO UNIX. How could have I written the following in 'C'? _time proc near mov eax,0dh ;Get time from OS, result in EAX db 9ah ; call far 0x7:0 dd 0 dw 07h mov ecx,4[esp] ;arg passed to time jecxz short time_done ;== NULL? mov [ecx],eax time_done: ret _time endp _lseek proc near mov eax,19 db 9ah ; call far 0x7:0 dd 0 dw 07h jc short cerror ; Carry set on error. ret cerror: mov _errno,eax ; errno = value returned by kernel sbb eax,eax ; return value = -1 ret _lseek endp Note that values must be put in a specific register (EAX) before doing a "far" call. ANSI doesn't recognize a 'far' or 'near' call and in this implementation of UNIX all 'normal' functions calls are near calls. Yet to 'talk' to the OS you must go through a 'far' call. Note also that the 'Carry' flag is set on error. Also note that in the case of lseek (required to implement fseek()) arguments are passed on the stack frame of the caller. lseek() cannot have it's own stack frame. So... just one of the many questions that could be asked having gone through this exercise... How do I get the carry flag status on return from a function call that I can't make, having passed parameters in registers I can't access from an ANSI conforming program? Surely I have missed an assumption you made someplace... this doesn't qualify as 'most enviroments'? Yet all other environments that I am familar with differ only in the details. -- joe@proto.com