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

M

_mario.lat

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.
[...]
"
 
C

Carramba

_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);
}

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.
[...]
"
 
K

Keith Thompson

_mario.lat said:
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.
 
R

Richard Tobin

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 }}}?
[/QUOTE]
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
 
K

Keith Thompson

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top