{"id":20358869,"url":"https://github.com/creativcoder/complex-c-expressions","last_synced_at":"2026-02-06T23:02:10.578Z","repository":{"id":32165937,"uuid":"35739158","full_name":"creativcoder/Complex-C-Expressions","owner":"creativcoder","description":"Guide to read complex c expressions AKA \"Right to Left Rule\"","archived":false,"fork":false,"pushed_at":"2015-05-16T21:02:53.000Z","size":308,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-20T04:57:19.351Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/creativcoder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-16T20:29:00.000Z","updated_at":"2018-08-07T07:34:53.000Z","dependencies_parsed_at":"2022-09-23T00:00:24.208Z","dependency_job_id":null,"html_url":"https://github.com/creativcoder/Complex-C-Expressions","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/creativcoder/Complex-C-Expressions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativcoder%2FComplex-C-Expressions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativcoder%2FComplex-C-Expressions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativcoder%2FComplex-C-Expressions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativcoder%2FComplex-C-Expressions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/creativcoder","download_url":"https://codeload.github.com/creativcoder/Complex-C-Expressions/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/creativcoder%2FComplex-C-Expressions/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29179565,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T22:12:24.066Z","status":"ssl_error","status_checked_at":"2026-02-06T22:12:09.859Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T23:29:15.203Z","updated_at":"2026-02-06T23:02:10.545Z","avatar_url":"https://github.com/creativcoder.png","language":null,"readme":"# Complex-C-Expressions\nGuide to read complex c expressions AKA \"Right to Left Rule\"\n\nThe \"right-left\" rule is a completely regular rule for deciphering C\ndeclarations.  It can also be useful in creating them.\n\nFirst, symbols.  Read\n\n     *\t\tas \"pointer to\"\t\t\t- always on the left side\n     [] \tas \"array of\"\t\t\t- always on the right side\n     ()\t\tas \"function returning\"\t\t- always on the right side\n\nas you encounter them in the declaration.\n\nSTEP 1\n------\nFind the identifier.  This is your starting point.  Then say to yourself,\n\"identifier is.\"  You've started your declaration.\n\nSTEP 2\n------\nLook at the symbols on the right of the identifier.  If, say, you find \"()\"\nthere, then you know that this is the declaration for a function.  So you\nwould then have \"identifier is function returning\".  Or if you found a \n\"[]\" there, you would say \"identifier is array of\".  Continue right until\nyou run out of symbols *OR* hit a *right* parenthesis \")\".  (If you hit a \nleft parenthesis, that's the beginning of a () symbol, even if there\nis stuff in between the parentheses.  More on that below.)\n\nSTEP 3\n------\nLook at the symbols to the left of the identifier.  If it is not one of our\nsymbols above (say, something like \"int\"), just say it.  Otherwise, translate\nit into English using that table above.  Keep going left until you run out of\nsymbols *OR* hit a *left* parenthesis \"(\".  \n\nNow repeat steps 2 and 3 until you've formed your declaration.  Here are some\nexamples:\n```c\n     int *p[];\n```\n1) Find identifier.         \n\u003e                                                                                                                    \n\u003e      \t\t\t     int *p[];     --------\u003e\u003e \"p is\"\n\u003e                         ^                                                                                  \t\n\n2) Move right until out of symbols or right parenthesis hit.\n\u003e                                                                                                                    \n\u003e      \t\t\t     int *p[];     --------\u003e\u003e \"p is an array of\"\n\u003e                         ^^   \n\n3) Can't move right anymore (out of symbols), so move left and find:\n\u003e                                                                                                                    \n\u003e      \t\t\t     int *p[];     --------\u003e\u003e \"p is array of pointer to\"\n\u003e                        ^   \n\n4) Keep going left and find:\n\u003e                                                                                                                    \n\u003e      \t\t\t     int *p[];     --------\u003e\u003e \"p is array of pointer to\"\n\u003e                    ^^^   \n   \n   (or \"p is an array where each element is of type pointer to int\")\n\n-------------------------------------------------------------------------------------------------------\nAnother example:\n\n   int *(*func())();\n\n1) Find the identifier.      int *(*func())();\n                                    ^^^^\n   \"func is\"\n\n2) Move right.               int *(*func())();\n                                        ^^\n   \"func is function returning\"\n\n3) Can't move right anymore because of the right parenthesis, so move left.\n                             int *(*func())();\n                                   ^\n   \"func is function returning pointer to\"\n\n4) Can't move left anymore because of the left parenthesis, so keep going\n   right.                    int *(*func())();\n                                           ^^\n   \"func is function returning pointer to function returning\"\n\n5) Can't move right anymore because we're out of symbols, so go left.\n                             int *(*func())();\n                                 ^\n   \"func is function returning pointer to function returning pointer to\"\n\n6) And finally, keep going left, because there's nothing left on the right.\n                             int *(*func())();\n                             ^^^\n   \"func is function returning pointer to function returning pointer to int\".\n\n\nAs you can see, this rule can be quite useful.  You can also use it to\nsanity check yourself while you are creating declarations, and to give\nyou a hint about where to put the next symbol and whether parentheses\nare required.\n\nSome declarations look much more complicated than they are due to array\nsizes and argument lists in prototype form.  If you see \"[3]\", that's\nread as \"array (size 3) of...\".  If you see \"(char *,int)\" that's read\nas \"function expecting (char *,int) and returning...\".  Here's a fun\none:\n\n                 int (*(*fun_one)(char *,double))[9][20];\n\nI won't go through each of the steps to decipher this one.\n\nOk.  It's:\n\n     \"fun_one is pointer to function expecting (char *,double) and \n      returning pointer to array (size 9) of array (size 20) of int.\"\n\nAs you can see, it's not as complicated if you get rid of the array sizes\nand argument lists:\n\n     int (*(*fun_one)())[][];\n\nYou can decipher it that way, and then put in the array sizes and argument\nlists later.\n\nSome final words:\n\nIt is quite possible to make illegal declarations using this rule,\nso some knowledge of what's legal in C is necessary.  For instance,\nif the above had been:\n\n     int *((*fun_one)())[][];\n\nit would have been \"fun_one is pointer to function returning array of array of\n                                          ^^^^^^^^^^^^^^^^^^^^^^^^\npointer to int\".  Since a function cannot return an array, but only a \npointer to an array, that declaration is illegal.\n\n\nIllegal combinations include:\n\n\t []() - cannot have an array of functions\n\t ()() - cannot have a function that returns a function\n\t ()[] - cannot have a function that returns an array\n\nIn all the above cases, you would need a set of parens to bind a *\nsymbol on the left between these () and [] right-side symbols in order\nfor the declaration to be legal.\n\nHere are some legal and illegal examples:\n```c\nExpressions        |      Evaluates To\n\nint i;             |      an int\nint *p;            |      an int pointer (ptr to an int)\nint a[];           |      an array of ints\nint f();           |      a function returning an int\nint **pp;          |      a pointer to an int pointer (ptr to a ptr to an int)\nint (*pa)[];       |      a pointer to an array of ints\nint (*pf)();       |      a pointer to a function returning an int\nint *ap[];         |      an array of int pointers (array of ptrs to ints)\nint aa[][];        |      an array of arrays of ints\nint af[]();        |      an array of functions returning an int (ILLEGAL)\nint *fp();         |      a function returning an int pointer\nint fa()[];        |      a function returning an array of ints (ILLEGAL)\nint ff()();        |      a function returning a function returning an int(ILLEGAL)\nint ***ppp;        |      a pointer to a pointer to an int pointer\nint (**ppa)[];     |      a pointer to a pointer to an array of ints\nint (**ppf)();     |      a pointer to a pointer to a function returning an int\nint *(*pap)[];     |      a pointer to an array of int pointers\nint (*paa)[][];    |      a pointer to an array of arrays of ints\nint (*paf)[]();    |      a pointer to a an array of functions returning an int(ILLEGAL)\nint *(*pfp)();     |      a pointer to a function returning an int pointer\nint (*pfa)()[];    |      a pointer to a function returning an array of ints(ILLEGAL)\nint (*pff)()();    |      a pointer to a function returning a function returning an int (ILLEGAL)\nint **app[];       |      an array of pointers to int pointers\nint (*apa[])[];    |      an array of pointers to arrays of ints\nint (*apf[])();    |      an array of pointers to functions returning an int\nint *aap[][];      |      an array of arrays of int pointers\nint aaa[][][];     |      an array of arrays of arrays of ints\nint aaf[][]();     |      an array of arrays of functions returning an int (ILLEGAL)\nint *afp[]();      |      an array of functions returning int pointers (ILLEGAL)\nint afa[]()[];     |      an array of functions returning an array of ints(ILLEGAL)\nint aff[]()();     |      an array of functions returning functions returning an int (ILLEGAL)\nint **fpp();       |      a function returning a pointer to an int pointer\nint (*fpa())[];    |      a function returning a pointer to an array of ints\nint (*fpf())();    |      a function returning a pointer to a function returning an int\nint *fap()[];      |      a function returning an array of int pointers (ILLEGAL)\nint faa()[][];     |      a function returning an array of arrays of ints (ILLEGAL)\nint faf()[]();     |      a function returning an array of functions returning an int (ILLEGAL)\nint *ffp()();      |      a function returning a function returning an int pointer (ILLEGAL)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreativcoder%2Fcomplex-c-expressions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcreativcoder%2Fcomplex-c-expressions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcreativcoder%2Fcomplex-c-expressions/lists"}