473,326 Members | 2,182 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,326 software developers and data experts.

help: define problem and meaning of {{{ and }}}.

for struct:
struct in6_addr {
uint8_t s6_addr[16];
};

is provided a costant:

#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}

what does means {{{, and }}}?
why can be used in a declaration only?
thankyou in advance,
MArio.

--------
I refer to:
http://www.faqs.org/rfcs/rfc3493.html
"[...]
The symbolic constant is named IN6ADDR_LOOPBACK_INIT and is
defined in <netinet/in.h>.
It can be used at declaration time ONLY; for example:

struct in6_addr loopbackaddr = IN6ADDR_LOOPBACK_INIT;

Like IN6ADDR_ANY_INIT, this constant cannot be used in an assignment
to a previously declared IPv6 address variable.
[...]
"
May 27 '07 #1
4 2180
_mario.lat skrev:
for struct:
struct in6_addr {
uint8_t s6_addr[16];
};

is provided a costant:
this is not a konstant, it is macro _ meaning that it will replate your
initialization in pre-compiler
#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}
#include <stdio.h>
#include <stdlib.h>

struct in6_addr{
unsigned int s6_addr[16];
};
/*
*you had to may brackets; the firs pair {} is for the struck
*initialization, the second pair {}, inside is for array initialization
*/

#define IN6ADDR_LOOPBACK_INIT {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}

int main(void){

int i;
struct in6_addr a = IN6ADDR_LOOPBACK_INIT ;
/*
*pre-compiler will replace it with {{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}
*/

for(i=0;i<16;i++){
printf("%d ", a.s6_addr[i]);
}

return EXIT_SUCCESS;
}
what does means {{{, and }}}?
why can be used in a declaration only?
thankyou in advance,
MArio.

--------
I refer to:
http://www.faqs.org/rfcs/rfc3493.html
"[...]
The symbolic constant is named IN6ADDR_LOOPBACK_INIT and is
defined in <netinet/in.h>.
It can be used at declaration time ONLY; for example:

struct in6_addr loopbackaddr = IN6ADDR_LOOPBACK_INIT;

Like IN6ADDR_ANY_INIT, this constant cannot be used in an assignment
to a previously declared IPv6 address variable.
[...]
"
May 27 '07 #2
"_mario.lat" <no**@libero.itwrites:
for struct:
struct in6_addr {
uint8_t s6_addr[16];
};

is provided a costant:

#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}

what does means {{{, and }}}?
{{{ is simply a sequence of three distinct { tokens.
Likewise for }}}.
why can be used in a declaration only?
[...]
I refer to:
http://www.faqs.org/rfcs/rfc3493.html
That RFC specifies the IN6ADDR_LOOPBACK_INIT, but it doesn't specify
how it's defined; the triple curly braces don't appear anywhere in the
RFC itself.

Some implementations do use triple braces in their definition of
IN6ADDR_LOOPBACK_INIT. Others don't.

IN6ADDR_LOOPBACK_INIT is intended to expand to an initializer for an
object of type struct in6_addr. If you look at the definition of type
"struct in6_addr", you'll probably see that it consists of an array
within a union within a structure. The definition uses one level of
braces for each level of the type definition.

Note that C is fairly lax about braces in initializers. You can
legally omit some braces; you can even add them in some cases:

int i = { 42 };

But IMHO it's best to have the structure of the initializer match the
structure of the type.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 27 '07 #3
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>struct in6_addr {
uint8_t s6_addr[16];
};

is provided a costant:

#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}

what does means {{{, and }}}?
>IN6ADDR_LOOPBACK_INIT is intended to expand to an initializer for an
object of type struct in6_addr. If you look at the definition of type
"struct in6_addr", you'll probably see that it consists of an array
within a union within a structure.
The OP quoted the definition of struct in6_addr (see above), and it
just consists of an array within the struct. So the mystery is why
there are 3 rather than 2 levels of brace.

Some implementations certainly do define it as a struct containing a
union as you suggested; perhaps the OP has a buggy implementation, or
has misread some #ifdefs or something like that.

-- Richard
--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
May 27 '07 #4
ri*****@cogsci.ed.ac.uk (Richard Tobin) writes:
In article <ln************@nuthaus.mib.org>,
Keith Thompson <ks***@mib.orgwrote:
>>struct in6_addr {
uint8_t s6_addr[16];
};

is provided a costant:

#define IN6ADDR_LOOPBACK_INIT {{{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1}}}

what does means {{{, and }}}?
>>IN6ADDR_LOOPBACK_INIT is intended to expand to an initializer for an
object of type struct in6_addr. If you look at the definition of type
"struct in6_addr", you'll probably see that it consists of an array
within a union within a structure.

The OP quoted the definition of struct in6_addr (see above), and it
just consists of an array within the struct. So the mystery is why
there are 3 rather than 2 levels of brace.

Some implementations certainly do define it as a struct containing a
union as you suggested; perhaps the OP has a buggy implementation, or
has misread some #ifdefs or something like that.
The quoted definition of struct s6_addr is from the RFC. Reading on
in the RFC:

The structure in6_addr above is usually implemented with an embedded
union with extra fields that force the desired alignment level in a
manner similar to BSD implementations of "struct in_addr". Those
additional implementation details are omitted here for simplicity.

An example is as follows:

struct in6_addr {
union {
uint8_t _S6_u8[16];
uint32_t _S6_u32[4];
uint64_t _S6_u64[2];
} _S6_un;
};
#define s6_addr _S6_un._S6_u8

Given such a definition, the triple braces are appropriate (though
single braces would also be legal).

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 27 '07 #5

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

Similar topics

5
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator='...
11
by: Mannequin* | last post by:
Hi all, I'm working on a quick program to bring the Bible into memory from a text file. Anyway, I have three questions to ask. First, is my implementation of malloc () correct in the program to...
13
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the...
10
by: Brett | last post by:
If I have many hard coded values such as file paths, file names, timeouts, etc, where is the best place to define them? Meaning, in the case something needs changing for example, rather than...
17
by: niraj.tiwari | last post by:
What is meaning of the following define:- #define x(argl...) x1(##argl)
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
45
by: davy.zou | last post by:
I have started learning c++ and I need help. I need to write a program, the question is as follows. At a post office, there are a certain number of 2, 7, and 9cents stamps, now, given a total...
4
by: venkat | last post by:
I have come across some preprossor statements, such as #define PPTR_int #define PPTR_str #define DDAR_baddr & #define DDAR_caddr & What do they mean, but when i compile the code with these...
5
by: MoslyChang | last post by:
Hi, All When I look at effective c++,item2 and item3. I have some basic questions , Does anyone be familar with this topic? it suggests const is perfer to #define, then I think how to replace...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.