Advertisement
tonylight2016

c语言#/##的使用

Nov 26th, 2020
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.05 KB | None | 0 0
  1.  
  2. #include <stdio.h>
  3.  
  4. typedef  struct struAVClass{
  5.     const char* class_name;
  6.     const char* (*item_name)(void* ctx);
  7.     const char* option;
  8. }AVClass;
  9.  
  10.  
  11. #define DEFINE_WRITER_CLASS(name)                   \
  12. static const char *name##_get_name(void *ctx)       \
  13. {                                                   \
  14.     return #name ;                                  \
  15. }                                                   \
  16. static const AVClass name##_class = {               \
  17.     .class_name = #name,                            \
  18.     .item_name  = name##_get_name,                  \
  19.     .option     = "name##_options"                  \
  20. }
  21.  
  22. static const char* test_options = "test_options";
  23. static const char* west_options = "west_options";
  24. DEFINE_WRITER_CLASS(test);
  25. DEFINE_WRITER_CLASS(west);
  26.  
  27. int main()
  28. {
  29.     printf("class_name=%s, item_name=%s, option=%s
  30. ", test_class.class_name, test_class.item_name(NULL), test_class.option);
  31.     printf("class_name=%s, item_name=%s, option=%s
  32. ", west_class.class_name, west_class.item_name(NULL), west_class.option);
  33.     return 0;
  34. }
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement