37

I have seen it used twice already in different libraries as an abbreviation, but I can't wrap my head around what it should mean.

For example here:

static int reformat_string(void * ctx, const unsigned char * stringVal,  
                       size_t stringLen)  
{  
    yajl_gen g = (yajl_gen) ctx;  
    return yajl_gen_status_ok == yajl_gen_string(g, stringVal, stringLen);  
}  

As far as I can tell, it is usually used for structs.

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Blub
  • 13,014
  • 18
  • 75
  • 102
  • While refactoring some piece of Java code, I changed variable name `ctx` to `context` which raised some questions from a reviewer. "Is `ctx` not clear enough?" In Java, I prefer fully spelt out variable names unless there is a very good reason to contract/abreviate. Hope this gives you some food for thought. – havryliuk Jun 23 '21 at 07:28

2 Answers2

58

It typically stands for "context". Usually this is some structure that gets passed around to functions in a library, used to maintain state (i.e., the context of the function call).

It's a preferable alternative to using global variables.

jamesdlin
  • 81,374
  • 13
  • 159
  • 204
0

By acronymsandslang.com It means "context". But You can look for other CTX meaning there

Sheeva
  • 33
  • 1