Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

/* ARGSUSED */ and other special comments

Tags:

c

comments

I've searched on SO and googled but I don't get meanings of them. What are they and their purposes? When are they used? I think that maybe I'm too late to see them in modern-day programming and in my generation.

Some of them AFAIS,

  • /* ARGSUSED */
  • /* VARARGS */
  • /* LINTLIBRARY */
  • /* NOSTRICT */

Example code with /* ARGSUSED */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <pthread.h>
#define BUFSIZE 1024
#define TEN_MILLION 10000000L


/* ARGSUSED */
void *threadout(void *args) {
    char buffer[BUFSIZE];
    char *c;
    struct timespec sleeptime;

    sleeptime.tv_sec = 0;
    sleeptime.tv_nsec = TEN_MILLION;
    snprintf(buffer, BUFSIZE, "This is a thread from process %ld\n",
             (long)getpid());
    c = buffer;
    /*****************start of critical section ********************/
    while (*c != '\0') {
        fputc(*c, stderr);
        c++;
        nanosleep(&sleeptime, NULL);
    }
    /*******************end of critical section ********************/
    return NULL;
}


int main(int argc, char *argv[]) {
    int error;
    int i;
    int n;
    pthread_t *tids;

    if (argc != 2){   /* check for valid number of command-line arguments */
        fprintf (stderr, "Usage: %s numthreads\n", argv[0]);
        return 1;
    }
    n = atoi(argv[1]);
    tids = (pthread_t *)calloc(n, sizeof(pthread_t));
    if (tids == NULL) {
        perror("Failed to allocate memory for thread IDs");
        return 1;
    }
    for (i = 0; i < n; i++)
        if (error = pthread_create(tids+i, NULL, threadout, NULL)) {
            fprintf(stderr, "Failed to create thread:%s\n", strerror(error));
            return 1;
        }
    for (i = 0; i < n; i++)
        if (error = pthread_join(tids[i], NULL)) {
            fprintf(stderr, "Failed to join thread:%s\n", strerror(error));
            return 1;
        }
    return 0;
}
like image 814
snr Avatar asked Aug 15 '17 10:08

snr


1 Answers

it is specific to the lint to suppress comments about the particular issue

What is the lint - from wikipedia

In computer programming, lint is a Unix utility that flags some suspicious and non-portable constructs (likely to be bugs) in C language source code; generically, lint or a linter is any tool that flags suspicious usage in software written in any computer language. The term lint-like behavior is sometimes applied to the process of flagging suspicious language usage. Lint-like tools generally perform static analysis of source code.

Lint as a term can also refer more broadly to syntactic discrepancies in general, especially in interpreted languages like JavaScript and Python. For example, modern lint checkers are often used to find code that doesn't correspond to certain style guidelines. Because these languages lack a compiling phase that shows a list of errors prior to execution, they can also be used as simple debuggers for common errors (showing syntactic discrepancies as errors) or hard to find errors such as heisenbugs (drawing attention on suspicious code as "possible errors").

Item

Description

/*NOTREACHED*/  Suppresses comments about unreachable code.
/*VARARGSNumber*/   Suppresses checking the following old style function declaration for varying numbers of arguments, but does check the data type of the first Number arguments. If you do not include a value for Number, the lint command checks no arguments (Number=0). The ANSI function prototypes should use the ellipsis to indicate unspecified parameters rather than this comment mechanism.
/*ARGSUSED*/    Suppresses warnings about function parameters not used within the function definition.
/*LINTLIBRARY*/     If you place this comment at the beginning of a file, the lint command does not identify unused functions and function parameters in the file. This is used when running the lint command on libraries.
/*NOTUSED*/     Suppresses warnings about unused external symbols, functions and function parameters in the file beginning at its point of occurrence. This is a superset of the /*LINTLIBRARY*/ comment directive, but applies also to external symbols. It is useful for suppressing warnings about unused function prototypes and other external object declarations.
/*NOTDEFINED*/  Suppresses warnings about used, but undefined external symbols and functions in the file beginning at its point of occurrence.
/*LINTSTDLIB*/  Permits a standard prototype-checking library to be formed from header files by making function prototype declarations appear as function definitions. This directive implicitly activates both the /*NOTUSED*/ and /*LINTLIBRARY*/ comment directives to reduce warning noise levels.

Maybe other tools use them as well.

You may find another special comments as well. For example many IDEs have their own tokens placed in the comments - for example to add something to the TO DO List

like image 70
0___________ Avatar answered Oct 31 '22 10:10

0___________