* difference between DECLARE_* and DEFINE_* macro namespaces ?
@ 2022-09-21 19:33 jim.cromie
2022-09-26 14:29 ` Rik van Riel
0 siblings, 1 reply; 2+ messages in thread
From: jim.cromie @ 2022-09-21 19:33 UTC (permalink / raw)
To: kernelnewbies
[-- Attachment #1.1: Type: text/plain, Size: 1724 bytes --]
difference between DECLARE_* and DEFINE_* macro namespaces ?
heres some quantitative observations
1st , raw usage counts
[jimc@frodo wk-test]$ ack DECLARE_\\w+ | wc
12541 30583 1030008
[jimc@frodo wk-test]$ ack \\bDECLARE_\\w+ | wc
11293 25240 897730
[jimc@frodo wk-test]$ ack \\bDEFINE_\\w+ | wc
14746 42085 1222994
[jimc@frodo wk-test]$ ack DEFINE_\\w+ | wc
16714 48172 1386881
used quite a lot. worth seeing the patterns...
this one seems telling it counts indent=0 lines,
ie Header lines, file-scope vars, global declarations etc.
]$ ack ^DEFINE_\\w+ | wc
7392 19578 661324
[jimc@frodo wk-test]$ ack 'static DECLARE_\w+' | wc
920 3025 80318
so about 1/12 of the DECLAREs have static outside them.
#defines determine how many PATTERN uses there are.
lets count them.
[jimc@frodo wk-test]$ ack '#define DECLARE_\w+' | wc
314 1384 27393
[jimc@frodo wk-test]$ ack '#define DEFINE_\w+' | wc
695 2734 55559
so, 2.3x DEFINE_/DECLARE_ definitions,
and 1.15x uses of those defns
interesting, not suggestive of anything..
lets look at one case
include/linux/spinlock_types_raw.h
71:#define DEFINE_RAW_SPINLOCK(x) raw_spinlock_t x =
__RAW_SPIN_LOCK_UNLOCKED(x)
its a variable declaration, expecting ';' in caller to close it.
[jimc@frodo wk-test]$ ack DEFINE_RAW_SPINLOCK | wc
140 293 10455
[jimc@frodo wk-test]$ ack 'static DEFINE_RAW_SPINLOCK' | wc
116 258 8705
[jimc@frodo wk-test]$ ack '^static DEFINE_RAW_SPINLOCK' | wc
107 231 8009
140 uses, most with static, most of those at file-scope
so, all that said, I havent gleaned any heuristics
does anyone want to offer a more qualitative review ?
[-- Attachment #1.2: Type: text/html, Size: 2898 bytes --]
[-- Attachment #2: Type: text/plain, Size: 170 bytes --]
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: difference between DECLARE_* and DEFINE_* macro namespaces ?
2022-09-21 19:33 difference between DECLARE_* and DEFINE_* macro namespaces ? jim.cromie
@ 2022-09-26 14:29 ` Rik van Riel
0 siblings, 0 replies; 2+ messages in thread
From: Rik van Riel @ 2022-09-26 14:29 UTC (permalink / raw)
To: jim.cromie, kernelnewbies
[-- Attachment #1.1: Type: text/plain, Size: 667 bytes --]
On Wed, 2022-09-21 at 13:33 -0600, jim.cromie@gmail.com wrote:
> difference between DECLARE_* and DEFINE_* macro namespaces ?
I am not sure there is a clear difference any more nowadays.
Both DECLARE_* and DEFINE_* seem to be used for both defining
a type and declaring an (often initialized) instance of that type.
For example, DEFINE_SPINLOCK creates an unlocked spinlock:
#define DEFINE_SPINLOCK(x) spinlock_t x = __SPIN_LOCK_UNLOCKED(x)
Meanwhile, DECLARE_RWSEM does the exact same thing, but for
the rw_semaphore:
#define DECLARE_RWSEM(name) \
struct rw_semaphore name = __RWSEM_INITIALIZER(name)
--
All Rights Reversed.
[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
[-- Attachment #2: Type: text/plain, Size: 170 bytes --]
_______________________________________________
Kernelnewbies mailing list
Kernelnewbies@kernelnewbies.org
https://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-09-26 14:38 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-21 19:33 difference between DECLARE_* and DEFINE_* macro namespaces ? jim.cromie
2022-09-26 14:29 ` Rik van Riel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).