Small note about Pointer coding standards

Epic has a standard about pointer placement.
UUserWidget *HUD should be UUserWidget* HUD

I only noticed because my IDE kept correcting me.

1 Like

The UUserWidget* HUD would be more of an industry standard and not just Unreal.
While not normally recommended, you can do UUserWidget *HUD, Hud2; and the second one would not be a pointer whereas UUserWidget* HUD, *Hud2; both are pointers.

I hope this makes sense.

EDITED to correct syntax

1 Like

@beegeedee In both of your declarations UUserWidget *HUD, HUD2; and UUserWidget* HUD, HUD2; HUD is a pointer and HUD2 isn’t.
If you wanted both to be a pointer you should declare them as UUserWidget *HUD, *HUD2;, this is one of the weirdnesses of C++.
I know this is an old post but just pointing this out so that people reading this in the future do not get confused.

EDITED::
The fact that the pointer * is next to the type means all are pointers. It has been this way since ansi C in the late 80s.

Putting the * in front of a variable makes just that variable the pointer of type.

Of course, declaring multiple variables on a single line would be rejected by most code checkers anyway (we use clang daily at work to perform a static analysis of the code) and usually is considered bad practice.

Tested this code with various compilers and couldn’t make it work. I don’t know if you are referring to something else, if that is the case could you explain?

Yeah, this turns out to be a C thing - we still use a lot of C code. I did some digging earlier myself. We don’t encounter this at work because we aren’t allowed to use raw pointers and supposed to avoid raw loops where possible and should only use modern algorithms and only smart pointers for the work I do. Also, declaring multiple variables on a single line is actually forbidden and the pipelines will fail for us before it even gets to the compile stage so I’d never actually do it this way anyway (and would completely fail for a raw pointer in the first place)

So, apologies. int* a,b; in C is not the same as in C++ but in C++ according to the C++ guidelines, you should never do that anyway.

As for implementing in a header, this becomes less relevant because usually you’ll be using pointers to expose things to blueprint by way of UPROPERTIES.

Privacy & Terms