N
Nudge
Hello,
Someone posted the following code to a different group:
void function2(int a, int b, int c) {
int exchange;
char buffer[3];
char *bufPt;
buffer[0] = 'A';
buffer[3] = 'B';
buffer[40] = 'B';
bufPt = buffer;
bufPt = bufPt + 1;
}
Note: buffer[3] and buffer[40] are out-of-bounds.
I answered: "[...] I believe 'function2' has undefined behavior.
In other words, the compiler is free to do anything it wants [...]"
Then someone commented: "No. Technically the program is fully
conforming. It is executing the program that gives undefined behaviour."
What does "Technically the program is fully conforming" mean?
Was my wording incorrect?
Perhaps source code cannot have undefined behavior, only executable
code can? I am somewhat confused. Could you please shed some light?
Someone posted the following code to a different group:
void function2(int a, int b, int c) {
int exchange;
char buffer[3];
char *bufPt;
buffer[0] = 'A';
buffer[3] = 'B';
buffer[40] = 'B';
bufPt = buffer;
bufPt = bufPt + 1;
}
Note: buffer[3] and buffer[40] are out-of-bounds.
I answered: "[...] I believe 'function2' has undefined behavior.
In other words, the compiler is free to do anything it wants [...]"
Then someone commented: "No. Technically the program is fully
conforming. It is executing the program that gives undefined behaviour."
What does "Technically the program is fully conforming" mean?
Was my wording incorrect?
Perhaps source code cannot have undefined behavior, only executable
code can? I am somewhat confused. Could you please shed some light?