The C compiler from Sun WorkShop assumes a type int
for any function or variable that is used in a module and not defined or declared externally. Any long
s and pointers used in this way are truncated by the compiler's implicit int
declaration. The appropriate extern
declaration for a function or variable should be placed in a header and not in the C module. The header should then be included by any C module that uses the function or variable. In the case of a function or variable defined by the system headers, the proper header should still be included in the code.
For example, because getlogin() is not declared, the following code:
int main(int argc, char *argv[]) { char *name = getlogin() printf("login = %s\n", name); return (0); }
produces the warnings:
warning: improper pointer/integer combination: op "=" warning: cast to pointer from 32-bit integer implicitly declared to return int getlogin printf
For better results, use::
#include <unistd.h> #include <stdio.h> int main(int argc, char *argv[]) { char *name = getlogin(); (void) printf("login = %s\n", name); return (0); }