[edk2-devel] [PATCH v6 14/22] ArmPkg: Add Universal/Smbios/ProcessorSubClassDxe
Leif Lindholm
leif at nuviainc.com
Thu Jan 28 11:32:41 UTC 2021
On Wed, Jan 27, 2021 at 21:53:57 -0700, Rebecca Cran wrote:
> On 1/25/21 12:04 PM, Leif Lindholm wrote:
> > On Thu, Jan 14, 2021 at 09:36:20 -0700, Rebecca Cran wrote:
> > > +// Sets the HII variable `x` if `pcd` isn't empty
> > > +#define SET_HII_STRING_IF_PCD_NOT_EMPTY(pcd, x) \
> > > + x##Str = (CHAR16 *)PcdGetPtr (pcd); \
> > > + if (StrLen (x##Str) > 0) { \
> > > + HiiSetString (mHiiHandle, x, x##Str, NULL); \
> > > + } \
> >
> > I am not a fan of preprocessor macros that require local variables
> > with magic names to exist.
> > Can this be rewritten as a helper function?
>
> Unfortunately PcdGetPtr uses token pasting, so a helper function won't work.
>
> Would the following be better?
>
> #define SetHiiStringIfPcdNotEmpty(Pcd, StringId) { \
> CHAR16 *Str = (CHAR16*)PcdGetPtr (Pcd); \
> if (StrLen (Str) > 0) { \
> HiiSetString (mHiiHandle, StringId, Str, NULL); \
> } \
> }
I'm mostly OK with that. I'd say it technically violates the coding
style because of assigning a value to Str on definition, but I can't
convince myself to care about that for a macro.
However, it still needs to have the name indicate that it's a macro,
so SET_HII_STRING_IF_PCD_NOT_EMPTY.
Best Regards,
Leif
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#70845): https://edk2.groups.io/g/devel/message/70845
Mute This Topic: https://groups.io/mt/79679256/1813853
Group Owner: devel+owner at edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [edk2-devel-archive at redhat.com]
-=-=-=-=-=-=-=-=-=-=-=-
More information about the edk2-devel-archive
mailing list