What does this dot syntax mean in the Pebble watch development tutorial? [duplicate]

南楼画角 提交于 2019-12-01 22:56:01

问题


I came across following code in Pebble watch app development tutorial:

// Set handlers to manage the elements inside the Window
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });

I cant understand this assignment to .load and .unload. Is this standard C? I don't think I have ever seen similar syntax before.


回答1:


This is standard c99.

It is combining compound literals

 (WindowHandlers) {}

and designated initializers

.load = main_window_load,
.unload = main_window_unload



回答2:


I believe it is standard C99, with an initialized struct constant with named fields in its initialization.

BTW, it is also a C extension -w.r.t. older C standards- (designated initializers) provided by GCC

For C11 standard, its final draft n1570 describes that syntax in "§6.7.9 Initializations"



来源:https://stackoverflow.com/questions/26949319/what-does-this-dot-syntax-mean-in-the-pebble-watch-development-tutorial

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!