The code below was copied from "The GNU C Library" here
In this question @Fatih suggested a change for the the code to compile, as I show in a comment below.
#include <signal.h>
#include <stdio.h>
#include <unistd.h> // This was inserted by Fatih
volatile struct two_words { int a, b; } memory;
void
handler(int signum)
{
printf ("%d,%d\n", memory.a, memory.b);
alarm (1);
}
int
main (void)
{
static struct two_words zeros = { 0, 0 }, ones = { 1, 1 };
signal (SIGALRM, handler);
memory = zeros;
alarm (1);
while (1)
{
memory = zeros;
memory = ones;
}
}
But the code still doesn't compile, as can be seen here. Error messages:
main.cpp: In function 'int main()':
main.cpp:19:13: error: passing 'volatile two_words' as 'this' argument discards qualifiers [-fpermissive]
19 | memory = zeros;
| ^~~~~
main.cpp:5:17: note: in call to 'constexpr two_words& two_words::operator=(const two_words&)'
5 | volatile struct two_words { int a, b; } memory;
| ^~~~~~~~~
main.cpp:23:17: error: passing 'volatile two_words' as 'this' argument discards qualifiers [-fpermissive]
23 | memory = zeros;
| ^~~~~
main.cpp:5:17: note: in call to 'constexpr two_words& two_words::operator=(const two_words&)'
5 | volatile struct two_words { int a, b; } memory;
| ^~~~~~~~~
main.cpp:24:17: error: passing 'volatile two_words' as 'this' argument discards qualifiers [-fpermissive]
24 | memory = ones;
| ^~~~
main.cpp:5:17: note: in call to 'constexpr two_words& two_words::operator=(const two_words&)'
5 | volatile struct two_words { int a, b; } memory;
| ^~~~~~~~~
What am I missing now?