Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

The Nash C Programming Language

Name: Anonymous 2021-04-02 22:06

Name: Anonymous 2021-04-12 15:20

>>35
Just redefine [] for something like num[bit]

int int."[]"(int bit) {
return ((*this)>>bit)&1;
}

int main() {
int x = 123;
if (x[0]) printf("%d is odd\n", x);
else printf("%d is even\n", x);
return 0;
}


Bit set would require defining `int int."[]="(int bit, int value)`

That is compared to C++, where operator[] leaks abstraction by returning a reference or some crazy wrapper. Because Straustrup is a schizo.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List