# stdnoreturn

***

**Note:** `stdnoreturn` is a type qualifier in C that indicates that a function does not return, or if it does, it can only return with an exception.

**1. Infinite Loop:**

```c
void infinite_loop() {
  while (1) {
    // Do something
  }
}
```

**2. Signal Handler:**

```c
void signal_handler(int signum) {
  // Handle signal
  exit(EXIT_FAILURE);
}
```

**3. Error Handling:**

```c
void error_handler(int error_code) {
  if (error_code != 0) {
    perror("Error occurred");
    exit(EXIT_FAILURE);
  }
}
```

**4. Assertions:**

```c
void assert_condition(bool condition) {
  assert(condition);
}
```

**5. Exceptions:**

```c
void throw_exception(const char* message) {
  throw(message);
}
```

**6. Call to exit:**

```c
void exit_application() {
  exit(EXIT_SUCCESS);
}
```

**7. Recursion without termination condition:**

```c
void recursive_without_termination() {
  recursive_without_termination();
}
```

**8. Longjmp with cleanup:**

```c
void longjmp_with_cleanup() {
  jmp_buf buf;
  if (setjmp(buf) == 0) {
    // Do something
    longjmp(buf, 1);
  }
  // Cleanup
}
```

**9. Wait for signal:**

```c
void wait_for_signal() {
  sigset_t mask;
  sigfillset(&mask);
  sigsuspend(&mask);
}
```

**10. Spinlock:**

```c
void spinlock_acquire() {
  while (__atomic_load_n(&lock, __ATOMIC_RELAXED)) {}
}
```

**11. Mutex:**

```c
void mutex_lock(pthread_mutex_t* mutex) {
  pthread_mutex_lock(mutex);
}
```

**12. Semaphore:**

```c
void semaphore_wait(sem_t* semaphore) {
  sem_wait(semaphore);
}
```

**13. Condition Variable:**

```c
void condition_variable_wait(pthread_cond_t* condition, pthread_mutex_t* mutex) {
  pthread_cond_wait(condition, mutex);
}
```

**14. Barrier:**

```c
void barrier_wait(pthread_barrier_t* barrier) {
  pthread_barrier_wait(barrier);
}
```

**15. Critical Section:**

```c
void critical_section(pthread_mutex_t* mutex) {
  pthread_mutex_lock(mutex);
  // Critical section
  pthread_mutex_unlock(mutex);
}
```

**16. Atomic Increment:**

```c
void atomic_increment(volatile int* counter) {
  __atomic_add_fetch(counter, 1, __ATOMIC_RELAXED);
}
```

**17. Atomic Decrement:**

```c
void atomic_decrement(volatile int* counter) {
  __atomic_sub_fetch(counter, 1, __ATOMIC_RELAXED);
}
```

**18. Atomic Exchange:**

```c
void atomic_exchange(volatile int* a, int b) {
  __atomic_exchange_n(a, b, __ATOMIC_RELAXED);
}
```

**19. Atomic Compare and Swap:**

```c
bool atomic_compare_and_swap(volatile int* a, int old_value, int new_value) {
  return __atomic_compare_exchange_n(a, &old_value, new_value, true, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
}
```

**20. Atomic Fetch and Add:**

```c
int atomic_fetch_and_add(volatile int* a, int b) {
  return __atomic_fetch_add(a, b, __ATOMIC_RELAXED);
}
```

**21. Atomic Fetch and Sub:**

```c
int atomic_fetch_and_sub(volatile int* a, int b) {
  return __atomic_fetch_sub(a, b, __ATOMIC_RELAXED);
}
```

**22. Atomic Fetch and And:**

```c
int atomic_fetch_and_and(volatile int* a, int b) {
  return __atomic_fetch_and(a, b, __ATOMIC_RELAXED);
}
```

**23. Atomic Fetch and Or:**

```c
int atomic_fetch_and_or(volatile int* a, int b) {
  return __atomic_fetch_or(a, b, __ATOMIC_RELAXED);
}
```

**24. Atomic Fetch and Xor:**

```c
int atomic_fetch_and_xor(volatile int* a, int b) {
  return __atomic_fetch_xor(a, b, __ATOMIC_RELAXED);
}
```

**25. Atomic Read-Modify-Write:**

```c
void atomic_read_modify_write(volatile int* a, int b) {
  *a = __atomic_add_fetch(a, b, __ATOMIC_RELAXED);
}
```

**26. Atomic Increment and Fetch:**

```c
int atomic_increment_and_fetch(volatile int* a) {
  return __atomic_add_fetch(a, 1, __ATOMIC_RELAXED);
}
```

**27. Atomic Decrement and Fetch:**

```c
int atomic_decrement_and_fetch(volatile int* a) {
  return __atomic_sub_fetch(a, 1, __ATOMIC_RELAXED);
}
```

**28. Atomic Exchange and Fetch:**

```c
int atomic_exchange_and_fetch(volatile int* a, int b) {
  return __atomic_exchange_n(a, b, __ATOMIC_RELAXED);
}
```

**29. Atomic Compare and Swap and Fetch:**

```c
int atomic_compare_and_swap_and_fetch(volatile int* a, int old_value, int new_value) {
  return __atomic_compare_exchange_n(a, &old_value, new_value, false, __ATOMIC_RELAXED, __ATOMIC_RELAXED);
}
```

**30. Atomic Fetch and Add and Fetch:**

```c
int atomic_fetch_and_add_and_fetch(volatile int* a, int b) {
  return __atomic_add_fetch(a, b, __ATOMIC_RELAXED);
}
```

**31. Atomic Fetch and Sub and Fetch:**

```c
int atomic_fetch_and_sub_and_fetch(volatile int* a, int b) {
  return __atomic_sub_fetch(a, b, __ATOMIC_RELAXED);
}
```

**32. Atomic Fetch and And and Fetch:**

```c
int atomic_fetch_and_and_and_fetch(volatile int* a, int b) {
  return __atomic_and_fetch(a, b, __ATOMIC_RELAXED);
}
```

**33. Atomic Fetch and Or and Fetch:**

```c
int atomic_fetch_and_or_and_fetch(volatile int* a, int b) {
  return __atomic_or_fetch(a, b, __ATOMIC_RELAXED);
}
```

**34. Atomic Fetch and Xor and Fetch:**

````c
int atomic_fetch_and_xor_and_fetch(volatile int* a, int b) {
  return __atomic_xor_fetch(a, b, __ATOMIC_RELAXED);
}

**35. Atomic Read-Modify-Write and Fetch:**
```c
int atomic_read_modify_write_and_fetch(volatile int* a, int b) {
  return __atomic_add_fetch(a, b, __ATOMIC_RELAXED);
}
````

**36. Flexible Array Member:**

```c
struct flexible_array {
  int n;
  int a[];
};
```

**37. Variable Length Array:**

```c
int a[n];
```

**38. Incomplete Array Type:**

```c
int a[];
```

**39. Pointer to Incomplete Array Type:**

```c
int (*a)[];
```

**40. Array of Incomplete Array Type:**

```c
int a[][n];
```

**41. Function with Variable Number of Arguments:**

```c
void foo(int n, ...) {
  va_list args;
  va_start(args, n);
  // ...
  va_end(args);
}
```

**42. Macro with Variable Number of Arguments:**

```c
#define foo(...) foo_impl(__VA_ARGS__)
```

**43. Macro with Variable Number of Arguments and Default Arguments:**

```c
#define foo(...) foo_impl(__VA_ARGS__, 42)
```

**44. Callback Function:**

```c
void foo(void* data) {
  // ...
}
```

**45. Thread Function:**

```c
void* foo(void* data) {
  // ...
  return NULL;
}
```

**46. Signal Handler Function:**

```c
void foo(int signum) {
  // ...
}
```

**47. Exception Handler Function:**

```c
void foo(void) {
  // ...
}
```

**48. Comparison Function for qsort:**

```c
int foo(const void* a, const void* b) {
  return strcmp(a, b);
}
```

**49. Input/Output Stream Function:**

```c
int foo(const char* format, ...) {
  va_list args;
  va_start(args, format);
  // ...
  va_end(args);
  return 0;
}
```

**50. Library Function:**

```c
int abs(int n) {
  return n < 0 ? -n : n;
}
```
