Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      abort

      From cppreference.com
      <c‎ |program
       
       
      Program support utilities
      Program termination
      abort
      (C99)
      Unreachable control flow
      Communicating with the environment
      Memory alignment query
      Signals
      Signal types
      Non-local jumps
      Types
       
      Defined in header<stdlib.h>
      void abort(void);
      (until C11)
      _Noreturnvoid abort(void);
      (since C11)
      (until C23)
      [[noreturn]]void abort(void);
      (since C23)

      Causes abnormal program termination unlessSIGABRT is being caught by a signal handler passed to signal and the handler does not return.

      Functions passed toatexit() are not called. Whether open resources such as files are closed is implementation defined. An implementation defined status is returned to the host environment that indicates unsuccessful execution.

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      (none)

      [edit]Notes

      POSIXspecifies that theabort() function overrides blocking or ignoring theSIGABRT signal.

      Some compiler intrinsics, e.g.__builtin_trap (gcc, clang, and icc) or__fastfail/__debugbreak (msvc), can be used to terminate the program as fast as possible.

      [edit]Example

      Run this code
      #include <stdio.h>#include <stdlib.h> int main(void){FILE*fp=fopen("data.txt","r");if(fp==NULL){fprintf(stderr,"error opening file data.txt in function main()\n");        abort();} /* Normal processing continues here. */fclose(fp);printf("Normal Return\n");return0;}

      Output:

      error opening file data.txt in function main()

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 7.22.4.1 The abort function (p: 255)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.22.4.1 The abort function (p: 350)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.20.4.1 The abort function (p: 315)
      • C89/C90 standard (ISO/IEC 9899:1990):
      • 4.10.4.1 The abort function

      [edit]See also

      causes normal program termination with cleaning up
      (function)[edit]
      registers a function to be called onexit() invocation
      (function)[edit]
      causes normal program termination without completely cleaning up
      (function)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/program/abort&oldid=167782"

      [8]ページ先頭

      ©2009-2025 Movatter.jp