Liste des Groupes | Revenir à cl c |
On 07/09/2024 02:44, Waldek Hebisch wrote:Bart <bc@freeuk.com> wrote:>On 06/09/2024 11:19, Waldek Hebisch wrote:Bart <bc@freeuk.com> wrote:>(You can balance it out by by requiring ASSIGN(&A, &B)!)This would not work in general, as I wrote it, the following are
valid:
assign(&a, 42)
assign(&a, a + 1)
but the second argument has no address, so your variant would not
work.
I believe that C's compound literals can give a reference to a+1:
#include <stdio.h>
>
void assign(int* lhs, int* rhs) {
*lhs = *rhs;
}
>
int main(void) {
int a=20;
>
assign(&a, &(int){a+1});
printf("a = %d\n", a);
}
Les messages affichés proviennent d'usenet.