CompuServe Thread

#C Help

5 messages in this thread
#40343From: CLEMENT DROLETApr 3, 1994 1:57 PM
I'm not familiar with C, most of my programming is done with Modula-2. So can anyone tell me what is the meaning of the __saveds word in the following example. BOOL __saveds GetData (struct MagicImage *pi, LONG offset, LONG rows, LONG *tags) Is it a directive to the compiler to expect arguments on the stack or something else? Thank's for your help. Clement
#40350From: Peter WadeApr 3, 1994 7:27 PM
It is a directive to the compiler. It makes the compiler include code at the start of the function to load the address of the near data section into register a4. I think you only need to specify this for functions which are called from somewhere other than within your program, for example callback routines or for functions in a shared library. It does not affect the way you pass arguments to the function if you are calling it. Peter Wade Autopiloting from London, England
#40381From: CLEMENT DROLETApr 5, 1994 10:47 PM
Peter, Thank you for the information, the example I'm trying to port from C to Modula-2 is indeed two callback routines that will be invoke by the Magic server when a program will want to put into or get from my image buffer some data. These routines are specified in the buffer inside a tag list as a int (*)() . Is this a pointer to a routine that returns a 32 bit integer? What a near data section refers to in C and do you know why the address of this section has to be load in A4 ? Clement
#40390From: Peter WadeApr 6, 1994 4:41 PM
The declaration : int (*func) () ; means that func is a pointer to a function which returns an integer. In SAS C integers are 32 bit by default, unless you use certain compiler switches. Strictly speaking it is bad form in C to declare something just as int if you care what length it should be. The near data section is just somewhere that the SAS compiler keeps global variables. Funcions compiled by SAS expect a4 to point to this section. If you are porting to another language the details of this are not important. However, if the C declaration includes __saveds or __interrupt it means the programmer expects these functions to be called from code that does not understand the environment that the compiler sets up for functions. You may need to do something similar if your compiler expects pointers to data sections in particular registers. Peter Wade Autopiloting from London, England
#40441From: CLEMENT DROLETApr 9, 1994 11:26 PM
Peter, Thank you for your informations about the "int (*func) ();" declaration and the a4 utilisation. My program experienced a bit of a problem beeing call by the callback routine, but I have find out what the problem was. In Modula-2 a procedure deallocates its parameters, in C the parameters are deallocated by the calling routine! I simply added a (*$P-*) compiler switch to have my procedure react as a C routine. Thank's again for your help. Clement