Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Buy land. They've stopped making it." -- Mark Twain


devel / comp.lang.c / What is this macro?

SubjectAuthor
* What is this macro?fl
+* Re: What is this macro?Lew Pitcher
|`* Re: What is this macro?Barry Schwarz
| `- Re: What is this macro?Lew Pitcher
+* Re: What is this macro?Keith Thompson
|`- Re: What is this macro?Chris M. Thomasson
`- Re: What is this macro?Kaz Kylheku

1
What is this macro?

<389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19244&group=comp.lang.c#19244

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:622a:1654:: with SMTP id y20mr18984186qtj.374.1637862772412;
Thu, 25 Nov 2021 09:52:52 -0800 (PST)
X-Received: by 2002:ac8:5b90:: with SMTP id a16mr19181378qta.300.1637862772271;
Thu, 25 Nov 2021 09:52:52 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Thu, 25 Nov 2021 09:52:52 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=70.112.196.212; posting-account=SZ_svQkAAACWRFG2bDA-zgq8ILyl4-vo
NNTP-Posting-Host: 70.112.196.212
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>
Subject: What is this macro?
From: rxjw...@gmail.com (fl)
Injection-Date: Thu, 25 Nov 2021 17:52:52 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 34
 by: fl - Thu, 25 Nov 2021 17:52 UTC

Hello everyone,

I create below code after reading some reference code. What is 'gSaveMap' in the main function?
The print message is:
50cff730

I know it is initialization of a doubly list. 'gSaveMap' is just a garbage of a random list head address?

Thanks in advance

///////////////////
#include <stdio.h>

#define INITIALIZE_LIST_HEAD_VAR(ListHead) {&(ListHead), &(ListHead)}

typedef struct _LIST_ENTRY LIST_ENTRY;

struct _LIST_ENTRY {
LIST_ENTRY* ForwardLink;
LIST_ENTRY* BackLink;
};

LIST_ENTRY gSaveMap = INITIALIZE_LIST_HEAD_VAR(gSaveMap);

int main()
{ printf("hello world\n");
printf("gSaveMap=%x\n", gSaveMap);
return 0;
}

Re: What is this macro?

<snok9u$a00$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19246&group=comp.lang.c#19246

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: What is this macro?
Date: Thu, 25 Nov 2021 18:22:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 85
Message-ID: <snok9u$a00$1@dont-email.me>
References: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 25 Nov 2021 18:22:54 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="d84dc90973e8cbb09d9ecbbde9e2eb4a";
logging-data="10240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jLiL5NDv1cxw+SNasOvOobFzwY6XHyAA="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:wIWzI4uqA9yz3FcfA8Di7TeVMfg=
 by: Lew Pitcher - Thu, 25 Nov 2021 18:22 UTC

On Thu, 25 Nov 2021 09:52:52 -0800, fl wrote:

> Hello everyone,
>
> I create below code after reading some reference code. What is
> 'gSaveMap' in the main function?
> The print message is:
> 50cff730
>
> I know it is initialization of a doubly list. 'gSaveMap' is just a
> garbage of a random list head address?
>
>
> Thanks in advance

Order changed for readability...

> ///////////////////
> #include <stdio.h>

> typedef struct _LIST_ENTRY LIST_ENTRY;

Defines a type alias "LIST_ENTRY" that represents a struct _LIST_ENTRY.
So, where-ever the compiler encounters a LIST_ENTRY type, it interprets
it as a
struct _LIST_ENTRY
type

> struct _LIST_ENTRY {
> LIST_ENTRY* ForwardLink; LIST_ENTRY* BackLink;
> };

Defines a
struct _LIST_ENTRY with members ForwardLink and BackLink

ForwardLink is of type LIST_ENTRY *, which, because of the
typedef, is really struct _LIST_ENTRY.

BackLink is of type LIST_ENTRY *, which, because of the
typedef, is really struct _LIST_ENTRY.
So, in all, the definition of
struct _LIST_ENTRY
contains
struct _LIST_ENTRY *ForwardLink;
and
struct _LIST_ENTRY *BackLink;

> #define INITIALIZE_LIST_HEAD_VAR(ListHead) {&(ListHead),&(ListHead)}

Macro definition for a string of parameterized tokens. Note that ListHead
is a placeholder variable, such that
INITIALIZE_LIST_HEAD_VAR(x)
will generate tokens
{ & ( x ) , & ( x ) }
while
INITIALIZE_LIST_HEAD_VAR(mylist)
will generate tokens
{ & ( mylist ) , & ( mylist ) }

> LIST_ENTRY gSaveMap = INITIALIZE_LIST_HEAD_VAR(gSaveMap);

Defines a
struct _LIST_ENTRY
called
gSaveMap
and initializes it with the pair of values
{ &(gSaveMap),&(gSaveMap) }

>
> int main()
> {
> printf("hello world\n"); printf("gSaveMap=%x\n", gSaveMap);
> return 0;
> }

--
Lew Pitcher
"In Skills, We Trust"

Re: What is this macro?

<871r34ggab.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19247&group=comp.lang.c#19247

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.lang.c
Subject: Re: What is this macro?
Date: Thu, 25 Nov 2021 11:57:00 -0800
Organization: None to speak of
Lines: 54
Message-ID: <871r34ggab.fsf@nosuchdomain.example.com>
References: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="9d0bb535dbeff490e7b28981ce186cfb";
logging-data="14451"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19QLQbv4m3LTFoj53W0LGOr"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:uxJKZb5TCH4OvHM5Y6w/lB1JJJo=
sha1:o1ok5lxaj9afrKiOaJKlMayMxTU=
 by: Keith Thompson - Thu, 25 Nov 2021 19:57 UTC

fl <rxjwg98@gmail.com> writes:
> I create below code after reading some reference code. What is 'gSaveMap' in the main function?
> The print message is:
> 50cff730
>
> I know it is initialization of a doubly list. 'gSaveMap' is just a garbage of a random list head address?
>
>
> Thanks in advance
>
> ///////////////////
> #include <stdio.h>
>
> #define INITIALIZE_LIST_HEAD_VAR(ListHead) {&(ListHead), &(ListHead)}
>
> typedef struct _LIST_ENTRY LIST_ENTRY;
>
> struct _LIST_ENTRY {
> LIST_ENTRY* ForwardLink;
> LIST_ENTRY* BackLink;
> };
>
> LIST_ENTRY gSaveMap = INITIALIZE_LIST_HEAD_VAR(gSaveMap);
>
> int main()
> {
> printf("hello world\n");
> printf("gSaveMap=%x\n", gSaveMap);
> return 0;
> }

Lew explained the macros. In your main function, you're calling printf
with a "%x" format specifier, which requires an argument of type
unsigned int. You're passing it an argument of a struct type.
The behavior is undefined, but one likely result is that you'll
print the value of the ForwardLink pointer in hexadecimal.

If you really want to print the values of the two pointer members, you
can do something like this (untested):

printf("gSaveMap.ForwardLink=%p\n", (void*)gSaveMap.ForwardLink);
printf("gSaveMap.BackLink=%p\n", (void*)gSaveMap.BackLink);

%p will print the pointer values in some implementation-defined
human-readable format (likely hexadecimal on most implementations).

I note that your doubly-linked list definition has forward and backward
links, but no payload, so there's not much you can do with it.
Presumably that will be added later.

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Re: What is this macro?

<snoruj$30c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19248&group=comp.lang.c#19248

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: What is this macro?
Date: Thu, 25 Nov 2021 12:33:20 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <snoruj$30c$1@dont-email.me>
References: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>
<871r34ggab.fsf@nosuchdomain.example.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 25 Nov 2021 20:33:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5600fdf00ab22d92aec5e2f142787c64";
logging-data="3084"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198T+uCT1ajwlksvuvB5RlmZt4xOR51k9g="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:Q/5/gIGF6kWU+3xpGDoZ80+Aq2c=
In-Reply-To: <871r34ggab.fsf@nosuchdomain.example.com>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 25 Nov 2021 20:33 UTC

On 11/25/2021 11:57 AM, Keith Thompson wrote:
> fl <rxjwg98@gmail.com> writes:
>> I create below code after reading some reference code. What is 'gSaveMap' in the main function?
>> The print message is:
>> 50cff730
>>
>> I know it is initialization of a doubly list. 'gSaveMap' is just a garbage of a random list head address?
>>
>>
>> Thanks in advance
>>
>> ///////////////////
>> #include <stdio.h>
>>
>> #define INITIALIZE_LIST_HEAD_VAR(ListHead) {&(ListHead), &(ListHead)}
>>
>> typedef struct _LIST_ENTRY LIST_ENTRY;
[...]
> I note that your doubly-linked list definition has forward and backward
> links, but no payload, so there's not much you can do with it.
> Presumably that will be added later.
>

One could use it for an intrusive list:

struct foo
{ LIST_ENTRY list;
int bar;
};

I am quite fond of them, and the offsetof macro comes in very handy.
Love the container_of macro... ;^)

Re: What is this macro?

<gp10qgh20t3l7cea9e4vf2eii3dn28cemu@4ax.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19249&group=comp.lang.c#19249

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: schwa...@delq.com (Barry Schwarz)
Newsgroups: comp.lang.c
Subject: Re: What is this macro?
Date: Thu, 25 Nov 2021 14:00:00 -0800
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <gp10qgh20t3l7cea9e4vf2eii3dn28cemu@4ax.com>
References: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com> <snok9u$a00$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Injection-Info: reader02.eternal-september.org; posting-host="3244f895d7256728bf6721e180e79876";
logging-data="5701"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ICwrV80n78wjFpjfSrMwo7J9q3yh8ggc="
Cancel-Lock: sha1:yVLRU07WVMUft73VhNsNs9/Sreo=
X-Newsreader: Forte Agent 4.2/32.1118
 by: Barry Schwarz - Thu, 25 Nov 2021 22:00 UTC

On Thu, 25 Nov 2021 18:22:54 -0000 (UTC), Lew Pitcher
<lew.pitcher@digitalfreehold.ca> wrote:

>On Thu, 25 Nov 2021 09:52:52 -0800, fl wrote:
>
>> Hello everyone,
>>
>> I create below code after reading some reference code. What is
>> 'gSaveMap' in the main function?
>> The print message is:
>> 50cff730
>>
>> I know it is initialization of a doubly list. 'gSaveMap' is just a
>> garbage of a random list head address?
>>
>>
>> Thanks in advance
>
>Order changed for readability...
>
>
>> ///////////////////
>> #include <stdio.h>
>
>> typedef struct _LIST_ENTRY LIST_ENTRY;
>
>Defines a type alias "LIST_ENTRY" that represents a struct _LIST_ENTRY.
>So, where-ever the compiler encounters a LIST_ENTRY type, it interprets
>it as a
> struct _LIST_ENTRY
>type
>
>
>> struct _LIST_ENTRY {
>> LIST_ENTRY* ForwardLink; LIST_ENTRY* BackLink;
>> };
>
>Defines a
> struct _LIST_ENTRY with members ForwardLink and BackLink
>
> ForwardLink is of type LIST_ENTRY *, which, because of the
> typedef, is really struct _LIST_ENTRY.
>
> BackLink is of type LIST_ENTRY *, which, because of the
> typedef, is really struct _LIST_ENTRY.

Of course you meant struct _LIST_ENTRY * for both

--
Remove del for email

Re: What is this macro?

<snp5cv$a00$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19250&group=comp.lang.c#19250

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.lang.c
Subject: Re: What is this macro?
Date: Thu, 25 Nov 2021 23:14:39 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <snp5cv$a00$2@dont-email.me>
References: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>
<snok9u$a00$1@dont-email.me> <gp10qgh20t3l7cea9e4vf2eii3dn28cemu@4ax.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 25 Nov 2021 23:14:39 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="38d5b6d887ac271fe8bfd22678de24fd";
logging-data="10240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8ZmktUuOugzfOqendF5ZTuP91RoUadb0="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:2m+rgUPVwtE8n0dqNfY/nxb5gIQ=
 by: Lew Pitcher - Thu, 25 Nov 2021 23:14 UTC

On Thu, 25 Nov 2021 14:00:00 -0800, Barry Schwarz wrote:

> On Thu, 25 Nov 2021 18:22:54 -0000 (UTC), Lew Pitcher
> <lew.pitcher@digitalfreehold.ca> wrote:
>
>>On Thu, 25 Nov 2021 09:52:52 -0800, fl wrote:
>>
>>> Hello everyone,
>>>
>>> I create below code after reading some reference code. What is
>>> 'gSaveMap' in the main function?
>>> The print message is:
>>> 50cff730
>>>
>>> I know it is initialization of a doubly list. 'gSaveMap' is just a
>>> garbage of a random list head address?
>>>
>>>
>>> Thanks in advance
>>
>>Order changed for readability...
>>
>>
>>> ///////////////////
>>> #include <stdio.h>
>>
>>> typedef struct _LIST_ENTRY LIST_ENTRY;
>>
>>Defines a type alias "LIST_ENTRY" that represents a struct _LIST_ENTRY.
>>So, where-ever the compiler encounters a LIST_ENTRY type, it interprets
>>it as a
>> struct _LIST_ENTRY
>>type
>>
>>
>>> struct _LIST_ENTRY {
>>> LIST_ENTRY* ForwardLink; LIST_ENTRY* BackLink;
>>> };
>>
>>Defines a
>> struct _LIST_ENTRY with members ForwardLink and BackLink
>>
>> ForwardLink is of type LIST_ENTRY *, which, because of the typedef, is
>> really struct _LIST_ENTRY.
>>
>> BackLink is of type LIST_ENTRY *, which, because of the typedef, is
>> really struct _LIST_ENTRY.
>
> Of course you meant struct _LIST_ENTRY * for both

Of course.

Thanks for the catch.

--
Lew Pitcher
"In Skills, We Trust"

Re: What is this macro?

<20211126104806.781@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19255&group=comp.lang.c#19255

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: 480-992-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: What is this macro?
Date: Fri, 26 Nov 2021 18:53:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <20211126104806.781@kylheku.com>
References: <389376e0-1196-4a36-8243-5713434297e2n@googlegroups.com>
Injection-Date: Fri, 26 Nov 2021 18:53:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="78441f0978f3598f64173b4fcf28b22b";
logging-data="12275"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19exwaPIUY2aqrE+X3LGrSlzK8ZklRT+4E="
User-Agent: slrn/1.0.3 (Linux)
Cancel-Lock: sha1:gVOWoCLj5nQ0FJmSRas03F1oh0Q=
 by: Kaz Kylheku - Fri, 26 Nov 2021 18:53 UTC

On 2021-11-25, fl <rxjwg98@gmail.com> wrote:
> Hello everyone,
>
> I create below code after reading some reference code. What is 'gSaveMap' in the main function?
> The print message is:
> 50cff730
>
> I know it is initialization of a doubly list. 'gSaveMap' is just a garbage of a random list head address?
>
> LIST_ENTRY gSaveMap = INITIALIZE_LIST_HEAD_VAR(gSaveMap);

This is some macro to generate a structure initializer: { .... }.

In C, structures can be initialized to refer to themselves; cycles are
allowed.

struct list entry g_list = { &g_list, &g_list };

here, the next and prev pointers point back to the g_list itself;
the list is doubly-linked and circular, rather than null-terminated
on both ends. The empty list is represented by an empty sentinel node
which points to itself. (This is not garbage at all, but an important
detail.)

If you want to hide that sentinel initialization behind the macro, the
macro needs to know the name of the object being initialized so it can
insert it:

#define list_entry_init(varname) { &varname, &varname }

now you can write:

struct list entry g_list = list_entry_init(g_list);

which generates the same thing.

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor