473,387 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Unusual C construct - What is it?


I was looking at some open source code, and found something that I had
never seen before:

const struct ast_datastore_info dialed_interface_info = {
.type ="dialed-interface",
.destroy = dialed_interface_destroy,
.duplicate = dialed_interface_duplicate,
};
What the heck are those dotted variables (?) fields(?). I don't recall
seeing that in the K&R.

I include the full file below.

-Ramon

---------------
/*
* Asterisk -- An open source telephony toolkit.
*
* Copyright (C) 1999 - 2007, Digium, Inc.
*
* Mark Michelson <mm********@digium.com>
*
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/

/*! \file
*
* \brief globally-accessible datastore information and callbacks
*
* \author Mark Michelson <mm********@digium.com>
*/

#include "asterisk/global_datastores.h"
#include "asterisk/linkedlists.h"

static void dialed_interface_destroy(void *data)
{
struct ast_dialed_interface *di = NULL;
AST_LIST_HEAD(, ast_dialed_interface) *dialed_interface_list = data;

if (!dialed_interface_list)
return;

AST_LIST_LOCK(dialed_interface_list);
while ((di = AST_LIST_REMOVE_HEAD(dialed_interface_list, list)))
ast_free(di);
AST_LIST_UNLOCK(dialed_interface_list);

AST_LIST_HEAD_DESTROY(dialed_interface_list);
ast_free(dialed_interface_list);
}

static void *dialed_interface_duplicate(void *data)
{
struct ast_dialed_interface *di = NULL;
AST_LIST_HEAD(, ast_dialed_interface) *old_list;
AST_LIST_HEAD(, ast_dialed_interface) *new_list = NULL;

if(!(old_list = data))
return NULL;

if(!(new_list = ast_calloc(1, sizeof(*new_list))))
return NULL;

AST_LIST_HEAD_INIT(new_list);
AST_LIST_LOCK(old_list);
AST_LIST_TRAVERSE(old_list, di, list) {
struct ast_dialed_interface *di2 = ast_calloc(1, sizeof(*di2) +
strlen(di->interface));
if(!di2) {
AST_LIST_UNLOCK(old_list);
dialed_interface_destroy(new_list);
return NULL;
}
strcpy(di2->interface, di->interface);
AST_LIST_INSERT_TAIL(new_list, di2, list);
}
AST_LIST_UNLOCK(old_list);

return new_list;
}

const struct ast_datastore_info dialed_interface_info = {
.type ="dialed-interface",
.destroy = dialed_interface_destroy,
.duplicate = dialed_interface_duplicate,
};

Dec 24 '07 #1
5 1591
Ramon F Herrera wrote:

[you posted to the wrong group]
I was looking at some open source code, and found something that I had
never seen before:

const struct ast_datastore_info dialed_interface_info = {
.type ="dialed-interface",
.destroy = dialed_interface_destroy,
.duplicate = dialed_interface_duplicate,
};
What the heck are those dotted variables (?) fields(?). I don't recall
seeing that in the K&R.
You won't. Its C99 syntax.

--
Ian Collins.
Dec 24 '07 #2
On Dec 24, 11:07*am, Ramon F Herrera <ra...@conexus.netwrote:
I was looking at some open source code, and found something that I had
never seen before:

const struct ast_datastore_info dialed_interface_info = {
* * * * .type ="dialed-interface",
* * * * .destroy = dialed_interface_destroy,
* * * * .duplicate = dialed_interface_duplicate,

};

What the heck are those dotted variables (?) fields(?). I don't recall
seeing that in the K&R.
This is part of C99 syntax and those variables are designated
initialisers. It makes it easier to track which fields are set during
that initialization. It is not valid in C++ though.
Dec 24 '07 #3
const struct ast_datastore_info dialed_interface_info = {
* * * * .type ="dialed-interface",
* * * * .destroy = dialed_interface_destroy,
* * * * .duplicate = dialed_interface_duplicate,

This is part of C99 syntax and those variables are designated
initialisers. It makes it easier to track which fields are set during
that initialization. It is not valid in C++ though.
If you need such a thing in C++, you have to use external
configuration files (try http://harpoon.sourceforge.net; my project to
be honest). I really wish it were a part of C++, as well as list
literals; and not only for initialization. For example:

draw_line( Point( x = 10, y = 25 ), Point( x = 50, y = 25 ) );

std::vector<intlist( { 1, 4, 5, 2 } );

Dec 25 '07 #4
On 2007-12-25 18:47, mc****@poczta.onet.pl wrote:
const struct ast_datastore_info dialed_interface_info = {
.type ="dialed-interface",
.destroy = dialed_interface_destroy,
.duplicate = dialed_interface_duplicate,

This is part of C99 syntax and those variables are designated
initialisers. It makes it easier to track which fields are set during
that initialization. It is not valid in C++ though.

If you need such a thing in C++, you have to use external
configuration files (try http://harpoon.sourceforge.net; my project to
be honest). I really wish it were a part of C++, as well as list
literals; and not only for initialization. For example:
The fact that C++ have constructors mitigates the problem slightly, and
if that is not enough you can use comments.

struct Point {
Point(intx, int y);
};

Point(/*x = */ 10, /*y = */ 25);

draw_line( Point( x = 10, y = 25 ), Point( x = 50, y = 25 ) );

std::vector<intlist( { 1, 4, 5, 2 } );
Will be in the next version of the standard, but with slightly different
syntax.

--
Erik Wikström
Dec 25 '07 #5
LR
Erik Wikström wrote:
On 2007-12-25 18:47, mc****@poczta.onet.pl wrote:
>>>const struct ast_datastore_info dialed_interface_info = {
.type ="dialed-interface",
.destroy = dialed_interface_destroy,
.duplicate = dialed_interface_duplicate,
This is part of C99 syntax and those variables are designated
initialisers. It makes it easier to track which fields are set during
that initialization. It is not valid in C++ though.
If you need such a thing in C++, you have to use external
configuration files (try http://harpoon.sourceforge.net; my project to
be honest). I really wish it were a part of C++, as well as list
literals; and not only for initialization. For example:

The fact that C++ have constructors mitigates the problem slightly, and
if that is not enough you can use comments.

struct Point {
Point(intx, int y);
};

Point(/*x = */ 10, /*y = */ 25);

>draw_line( Point( x = 10, y = 25 ), Point( x = 50, y = 25 ) );

The named parameter idiom might be useful,
http://www.parashift.com/c++-faq-lit...html#faq-10.18

LR

Dec 25 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert | last post by:
On Windows my python 2.2 application (using win32ui GUI, ...) some times simply crashes when I work with the GUI. Tooltips are involved; the app crashes on mouse moves). The GUI-Window disapears...
6
by: Lasse Skyum | last post by:
I'm currently learning STL and I hate not knowing what is gooing on "inside" STL... not because I really _need_ to know it to develop my game project, but that's just my nature... like most of you...
2
by: Wiseguy | last post by:
I'm in the process of trying to create my own lean, mean, uber linux distro and have bootstrapped a prototype system to build upon. I'm using the gcc 3.4.3 compiler and am getting an error that I...
4
by: Larry R Harrison Jr | last post by:
I have an Access 2000/XP with an unusual autonumber scheme; I can't figure out how it generates its very unique value. I have the database temporarily located at this website: ...
12
by: Laser Lu | last post by:
Hello, everybody, do you know how to use this Grouping Construct? (?> ) I've found its reference on MSDN, but still can not understand it totally. The following is its description: ...
3
by: Farooq Khan | last post by:
why does Response.Write in a method of code-beind class when called from inpage code (i.e in <%---%>), after creating object of that class, fails when called while it works perfectly ok while...
2
by: gangesmaster | last post by:
finally, i opened a wiki for Construct, the "parsing made fun" library. the project's page: http://pyconstruct.sourceforge.net/ the project's wiki: http://pyconstruct.wikispaces.com/ (anyone can...
3
by: Csaba Gabor | last post by:
If I do not have the indicated Word document open (on my Win XP Pro machine with PHP 5.2), the following will open and display it: <?php $path = "c:\\path\\to\\word\\document\\mydoc.doc"; $doc...
7
by: brett.estabrook | last post by:
I have written a multi-threaded c# windows service in .net 1.1 (Visual Studio .net 2003). The service has several threads that poll a Sql 6.5 database on another machine. Each thread will execute a...
10
by: sheldonlg | last post by:
I got an unusual request. One customer wants a password/access made available to a user that is valid for only, say, ten minutes. I know that I can enforce this by having a revalidation of the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.