Skip to content

Instantly share code, notes, and snippets.

@parthibx24
Last active May 15, 2020 15:14
Show Gist options
  • Select an option

  • Save parthibx24/51d718747375c5560aa6b39367324b45 to your computer and use it in GitHub Desktop.

Select an option

Save parthibx24/51d718747375c5560aa6b39367324b45 to your computer and use it in GitHub Desktop.
method chaining in c. definitely not c a n c e r .
#include <stdio.h>
/* not good way
typedef struct dk {
void (* setbro) (int);
int watbro;
} dk;
typedef struct {
dk (* setbro) (int);
int watbro;
} nn; */
/* kinda good way 1 *\/
typedef struct gStruct {
struct gStruct (* setbro) (int);
int watbro;
} nn; */
/* kinda good way 2 *\/
struct gStruct {
struct gStruct (* setbro) (int);
int watbro;
}; */
/* kinda good way 3 */
typedef struct nn {
struct nn (* setbro) (int);
int watbro;
} nn;
/* prolly not kinda good way 4 *\/
struct mango {
struct mango (* setbro) (int);
int watbro;
} nnno = {};
typedef struct nnno nn; */
nn pp;
nn bruh(int i) {
pp.watbro = i;
return pp;
}
nn kk() {
pp.setbro = &bruh;
return pp;
}
int main()
{
printf("Hello World %d",
kk()
.setbro(69)
.watbro);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment