[an error occurred while processing this directive]
HP OpenVMS SystemsC Programming Language |
Compaq C
|
Previous | Contents | Index |
The following example and explanation shows how to use the Compaq C RTL time functions to print the current time:
#include <stdio.h> #include <time.h> main () { time_t t; t = time((time_t)0); printf ("The current time is: %s\n",asctime (localtime (&t))); } |
This example:
Sends the signal SIGABRT that terminates execution of the program.
#include <stdlib.h>void abort (void);
Returns the absolute value of an integer.
#include <stdlib.h>int abs (int x);
x
An integer.
x The absolute value of the input argument. If the argument is LONG_MIN, abs returns LONG_MIN because --LONG_MIN cannot fit in an int variable.
Checks a file to see whether a specified access mode is allowed. This function only checks UIC protection; ACLs are not checked.
Note
The access function does not accept network files as arguments.
#include <unistd.h>int access (const char *file_spec, int mode);
file_spec
A character string that gives an OpenVMS or UNIX style file specification. The usual defaults and logical name translations are applied to the file specification.mode
Interpreted as shown in Table REF-1.
Table REF-1 Interpretation of the mode Argument Mode Argument Access Mode F_OK Tests to see if the file exists X_OK Execute W_OK Write (implies delete access) R_OK Read Combinations of access modes are indicated by ORing the values. For example, to check to see if a file has RWED access mode, invoke access as follows:
access (file_spec, R_OK | W_OK | X_OK);
0 Indicates that the access is allowed. --1 Indicates that the access is not allowed.
#include <unistd.h> #include <stdlib.h> #include <stdio.h> main() { if (access("sys$login:login.com", F_OK)) { perror("ACCESS - FAILED"); exit(2); } }
Returns the arc cosine of its argument.
#include <math.h>double acos (double x);
float acosf (float x); (ALPHA ONLY)
long double acosl (long double x); (ALPHA ONLY)
double acosd (double x); (ALPHA ONLY)
float acosdf (float x); (ALPHA ONLY)
long double acosdl (long double x); (ALPHA ONLY)
x
A radian expressed as a real value in the domain [-1,1].
The acos functions compute the principal value of the arc cosine of x in the range [0,Pi sign] radians for x in the domain [-1,1].The acosd functions compute the principal value of the arc cosine of x in the range [0,180] degrees for x in the domain [-1,1].
For abs (x) > 1, the value of acos (x) is 0, and errno is set to EDOM.
Returns the hyperbolic arc cosine of its argument.
#include <math.h>double acosh (double x);
float acoshf (float x);
long double acoshl (long double x);
x
A radian expressed as a real value in the domain [1, +Infinity].
The acosh functions return the hyperbolic arc cosine of x for x in the domain [1, +Infinity], where acosh (x) = ln(x + sqrt(x**2 - 1)).The acosh function is the inverse function of cosh where acosh ( cosh (x)) = |x|.
x < 1 is an invalid argument.
Add a character to the window at the current position of the cursor.
#include <curses.h>int addch (char ch);
int waddch (WINDOW *win, char ch);
win
A pointer to the window.ch
The character to be added. A new-line character (\n) clears the line to the end, and moves the cursor to the next line at the same x coordinate. A return (\r) moves the cursor to the beginning of the line on the window. A tab (\t) moves the cursor to the next tabstop within the window.
When the waddch function is used on a subwindow, it writes the character onto the underlying window as well.The addch routine performs the same function as waddch , but on the stdscr window.
The cursor is moved after the character is written to the screen.
OK Indicates success. ERR Indicates that writing the character would cause the screen to scroll illegally. For more information, see the scrollok function in this section.
Add the string pointed to by str to the window at the current position of the cursor.
#include <curses.h>int addstr (char *str);
int waddstr (WINDOW *win, char *str);
win
A pointer to the window.str
A pointer to a character string.
When the waddstr function is used on a subwindow, the string is written onto the underlying window as well.The addstr routine performs the same function as waddstr , but on the stdscr window.
The cursor position changes as a result of calling this routine.
OK Indicates success. ERR Indicates that the function causes the screen to scroll illegally, but it places as much of the string onto the window as possible. For more information, see the scrollok function in this section.
Sends the signal SIGALRM (defined in the <signal.h> header file) to the invoking process after the number of seconds indicated by its argument has elapsed.
#include <unistd.h>unsigned int alarm (unsigned int seconds); (ISO POSIX-1)
int alarm (unsigned int seconds); (COMPATABILITY)
seconds
Has a maximum limit of LONG_MAX seconds.
Calling the alarm function with a 0 argument cancels any pending alarms.Unless it is caught or ignored, the signal generated by alarm terminates the process. Successive alarm calls reinitialize the alarm clock. Alarms are not stacked.
Because the clock has a 1-second resolution, the signal may occur up to 1 second early. If the SIGALRM signal is caught, resumption of execution may be held up due to scheduling delays.
When the SIGALRM signal is generated, a call to SYS$WAKE is generated whether or not the process is hibernating. The pending wake causes the current pause () to return immediately (after completing any function that catches the SIGALRM).
n The number of seconds remaining from a previous alarm request.
Converts a broken-down time in a tm structure into a 26-character string in the following form:
Sun Sep 16 01:03:52 1984\n\0All fields have a constant width.
#include <time.h>char *asctime (const struct tm *timeptr);
char *asctime_r (const struct tm *timeptr, char *buffer); (ISO POSIX-1)
timeptr
A pointer to a structure of type tm , which contains the broken-down time.The tm structure is defined in the <time.h> header file, and also shown in Table REF-4 in the description of localtime .
buffer
A pointer to a character array that is at least 26 bytes long. This array is used to store the generated date-and-time string.
The asctime and asctime_r functions convert the contents of tm into a 26-character string and returns a pointer to the string.The difference between asctime_r and asctime is that the former puts the result into a user-specified buffer. The latter puts the result into thread-specific static memory allocated by the Compaq C RTL, which can be overwritten by subsequent calls to ctime or asctime ; you must make a copy if you want to save it.
On success, asctime returns a pointer to the string; asctime_r returns its second argument. On failure, these functions return the NULL pointer.
See the localtime function in this section for a list of the members in tm .
Note
Generally speaking, UTC-based time functions can affect in-memory time-zone information, which is process-wide data. However, if the system time zone remains the same during the execution of the application (which is the common case) and the cache of timezone files is enabled (which is the default), then the _r variant of the time functions asctime_r , ctime_r , gmtime_r and localtime_r , is both thread-safe and AST-reentrant.
If, however, the system time zone can change during the execution of the application or the cache of timezone files is not enabled, then both variants of the UTC-based time functions belong to the third class of functions, which are neither thread-safe nor AST-reentrant.
x A pointer to the string, if successful. NULL Indicates failure.
Returns the arc sine of its argument.
#include <math.h>double asin (double x);
float asinf (float x); (ALPHA ONLY)
long double asinl (long double x); (ALPHA ONLY)
double asind (double x); (ALPHA ONLY)
float asindf (float x); (ALPHA ONLY)
long double asindl (long double x); (ALPHA ONLY)
x
A radian expressed as a real number in the domain [-1, 1].
The asin functions compute the principal value of the arc sine of x in the range [-Pi sign/2,Pi sign/2] radians for x in the domain [-1,1].The asind functions compute the principal value of the arc sine of x in the range [-90,90] degrees for x in the domain [-1,1].
When abs (x) is greater than 1.0, the value of asin (x) is 0, and errno is set to EDOM.
Returns the hyperbolic arc sine of its argument.
#include <math.h>double asinh (double x);
float asinhf (float x);
long double asinhl (long double x);
x
A radian expressed as a real value in the domain [-Infinity, +Infinity].
The asinh functions return the hyperbolic arc sine of x for x in the domain [-Infinity, +Infinity], where asinh (x) = ln(x + sqrt(x**2 + 1)).The asinh function is the inverse function of sinh where asinh ( sinh (x)) = x.
Used for implementing run-time diagnostics in programs.
#include <assert.h>void assert (int expression);
expression
An expression that has an int type.
When assert is executed, if expression is false (that is, it evaluates to 0), assert writes information about the particular call that failed (including the text of the argument, the name of the source file, and the source line number; the latter two are respectively the values of the preprocessing macros __FILE__ and __LINE__) to the standard error file in an implementation-defined format. Then, it calls the abort function.The assert function writes a message in the following form:
Assertion failed: expression, file aaa, line nnnIf expression is true (that is, it evaluates to nonzero) or if the signal SIGABRT is being ignored, assert returns no value.
Note
If a null character ('\0') is part of the expression being asserted, then only the text up to and including the null character is printed, since the null character effectively terminates the string being output.Compiling with the CC command qualifier /DEFINE=NDEBUG or with the preprocessor directive #define NDEBUG ahead of the #include assert statement causes the assert function to have no effect.
#include <stdio.h> #include <assert.h> main() { printf("Only this and the assert\n"); assert(1 == 2); /* expression is FALSE */ /* abort should be called so the printf will not happen. */ printf("FAIL abort did not execute"); }
#include <math.h>double atan (double x);
float atanf (float x); (ALPHA ONLY)
long double atanl (long double x); (ALPHA ONLY)
double atand (double x); (ALPHA ONLY)
float atandf (float x); (ALPHA ONLY)
long double atandl (long double x); (ALPHA ONLY)
x
A radian expressed as a real number.
The atan functions compute the principal value of the arc tangent of x in the range [-Pi sign/2,Pi sign/2] radians.The atand functions compute the principal value of the arc tangent of x in the range [-90,90] degrees.
#include <math.h>double atan2 (double y, double x);
float atan2f (float y, float x); (ALPHA ONLY)
long double atan2l (long double y, long double x); (ALPHA ONLY)
double atand2 (double y, double x); (ALPHA ONLY)
float atand2f (float y, float x); (ALPHA ONLY)
long double atand2l (long double y, long double x); (ALPHA ONLY)
y
A radian expressed as a real number.x
A radian expressed as a real number.
The atan2 functions compute the principal value of the arc tangent of y/x in the range [-Pi sign,Pi sign] radians. The sign of atan2 and atan2f is determined by the sign of y. The value of atan2 (y,x) is computed as follows, where f is the number of fraction bits associated with the data type:
Value of Input Arguments Angle Returned x = 0 or y/x > 2**( f+1) Pi sign/2 * (sign y) x > 0 and y/x <= 2**( f+1) atan( y/x) x < 0 and y/x <= 2**( f+1) Pi sign * (sign y) + atan(y/x) The atand2 functions compute the principal value of the arc tangent of y/x in the range [-180,180] degrees. The sign of atand2 and atand2f is determined by the sign of y.
The following are invalid arguments for the atan2 and atand2 functions:
Function Exceptional Argument atan2, atan2f, atan2l x = y = 0 atan2, atan2f, atan2l | x| = | y| = Infinity atand2, atand2f, atand2l x = y = 0 atand2, atand2f, atand2l | x| = | y| = Infinity
Previous | Next | Contents | Index |