473,799 Members | 3,671 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_i nfo dialed_interfac e_info = {
.type ="dialed-interface",
.destroy = dialed_interfac e_destroy,
.duplicate = dialed_interfac e_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********@dig ium.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********@dig ium.com>
*/

#include "asterisk/global_datastor es.h"
#include "asterisk/linkedlists.h"

static void dialed_interfac e_destroy(void *data)
{
struct ast_dialed_inte rface *di = NULL;
AST_LIST_HEAD(, ast_dialed_inte rface) *dialed_interfa ce_list = data;

if (!dialed_interf ace_list)
return;

AST_LIST_LOCK(d ialed_interface _list);
while ((di = AST_LIST_REMOVE _HEAD(dialed_in terface_list, list)))
ast_free(di);
AST_LIST_UNLOCK (dialed_interfa ce_list);

AST_LIST_HEAD_D ESTROY(dialed_i nterface_list);
ast_free(dialed _interface_list );
}

static void *dialed_interfa ce_duplicate(vo id *data)
{
struct ast_dialed_inte rface *di = NULL;
AST_LIST_HEAD(, ast_dialed_inte rface) *old_list;
AST_LIST_HEAD(, ast_dialed_inte rface) *new_list = NULL;

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

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

AST_LIST_HEAD_I NIT(new_list);
AST_LIST_LOCK(o ld_list);
AST_LIST_TRAVER SE(old_list, di, list) {
struct ast_dialed_inte rface *di2 = ast_calloc(1, sizeof(*di2) +
strlen(di->interface));
if(!di2) {
AST_LIST_UNLOCK (old_list);
dialed_interfac e_destroy(new_l ist);
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_i nfo dialed_interfac e_info = {
.type ="dialed-interface",
.destroy = dialed_interfac e_destroy,
.duplicate = dialed_interfac e_duplicate,
};

Dec 24 '07 #1
5 1610
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_i nfo dialed_interfac e_info = {
.type ="dialed-interface",
.destroy = dialed_interfac e_destroy,
.duplicate = dialed_interfac e_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_i nfo dialed_interfac e_info = {
* * * * .type ="dialed-interface",
* * * * .destroy = dialed_interfac e_destroy,
* * * * .duplicate = dialed_interfac e_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_i nfo dialed_interfac e_info = {
* * * * .type ="dialed-interface",
* * * * .destroy = dialed_interfac e_destroy,
* * * * .duplicate = dialed_interfac e_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<int list( { 1, 4, 5, 2 } );

Dec 25 '07 #4
On 2007-12-25 18:47, mc****@poczta.o net.pl wrote:
const struct ast_datastore_i nfo dialed_interfac e_info = {
.type ="dialed-interface",
.destroy = dialed_interfac e_destroy,
.duplicate = dialed_interfac e_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<int list( { 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.o net.pl wrote:
>>>const struct ast_datastore_i nfo dialed_interfac e_info = {
.type ="dialed-interface",
.destroy = dialed_interfac e_destroy,
.duplicate = dialed_interfac e_duplicate,
This is part of C99 syntax and those variables are designated
initialiser s. 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
configuratio n 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
13227
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 and only the following message is yielded (from python-core?) " This application has requested the Runtime to terminate it in an unusual way. Please contact the application's support team for more information. "
6
4656
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 at this grounp I suspect. So the question is: How does a std::vector construct and destruct the elements in it? I know it has something to do with an allocator... Suppose I wrote:
2
1736
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 have to question. Some of the code I'm compiling places labels at the end of a construct, either as the destination of a goto or even something as benign as a default: label in a switch statement. starting with 3.4.3 (but not before) I'm...
4
2271
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: http://www.dbases.net/tmp/Tuscon2k.zip The field is called ****Company_Id**** in the table "Companies." There are LOTS of other tables linked to it but I deleted all of them because I was able to decipher that they aren't responsible for helping to delete this
12
2668
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: Nonbacktracking subexpression (also known as a "greedy" subexpression). The subexpression is fully matched once, and then does not participate piecemeal
3
1704
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 calling the same method same way except for creating object instead directly calling the method? i get this when trying to do that:- ************************************************** Response is not available in this context. Description: An...
2
1354
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 edit) so now we have one place where people can share inventory constructs, questions-and-answers, patches, documentation and more. enjoy.
3
4892
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 = new COM($path); $doc->Application->visible = true; ?> However, there will be several identical warnings (14 in number)
7
10183
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 stored procedure, and the results are used to determine if there is anything for this particular thread to do. My problem is that I periodically get exceptions from places that normally shouldn't get exceptions. The service can run find for...
10
1431
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 password every time the user changes a page. This, though, seems like a a lot of overhead in having to make a db call every time a page is changed. I also thought about setting a timer for ten minutes, and on firing of that timer unset a session...
0
9543
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10237
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10029
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7567
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6808
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5588
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3761
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.