/ *惊奇* /和其他特殊注释 [英] /* ARGSUSED */ and other special comments

查看:64
本文介绍了/ *惊奇* /和其他特殊注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索过SO,并在Google上搜索,但我没有得到它们的含义。它们是什么及其目的?什么时候使用?我认为也许我来不及在现代编程和我们这一代中看到它们。

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.

其中一些AFAIS,

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

带有 / * 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;
}


推荐答案

它特定于 lint 禁止发表有关特定问题的评论

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

什么是皮棉-来自维基百科

What is the lint - from wikipedia


在计算机编程中,lint是Unix实用程序,用于标记C
语言源中的某些
可疑和不可移植的构造(可能是bug)。码;通常,皮棉或短绒棉是指任何以任何计算机语言编写的软件中
标记可疑使用的工具。
类似棉绒的行为有时用于
标记可疑语言使用的过程。类似于Lint的工具通常会对源代码执行
静态分析。

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这个术语也可以更广泛地指代语法差异
,特别是在JavaScript和
Python等解释型语言中。例如,现代的棉绒检查器通常用于查找与某些样式指南不符的代码
。由于这些
语言缺少在执行
之前显示错误列表的编译阶段,因此它们也可以用作常见错误
(将语法差异显示为错误)的简单调试器,或者很难查找错误
,例如heisenbugs(提请注意可疑代码为可能的
错误)。

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").

项目

说明

/*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.

您可能还会发现其他特殊评论。例如,许多IDE在注释中放置了自己的令牌-例如,将某些东西添加到待办事项列表中。

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

这篇关于/ *惊奇* /和其他特殊注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆