'Does adding a star after a pointer struct definition make it a double pointer?

I have a struct

typedef struct hash_entry_{
   char *string;
   void *data;
   struct hash_entry *next;
}hash_entry, *p_entry;

I am referencing p_entry later in my code like so,

p_entry *temp = table;

does this make temp a double-pointer since I am adding an extra * before p_entry. I am confused on the point of even adding p_entry in my code when I can use hash_entry* as a pointer to a struct of hash_entry_ type.



Solution 1:[1]

does this make temp a double-pointer

Yes it does. But please use the term pointer-to-pointer, not to confuse things with double*.

The manner of "Hungarian notation" and other confused styles where you add a p in front of a type name to indicate that a pointer was hidden beneath it has been massively criticised over the years, the most well-known case is the Windows API. This is old, bad style that refuses to die.

In modern programming, there is a strong C programmer consensus that:

  • Pointers should never be hidden underneath typedef because it's very confusing for everyone including the person who wrote the code, as you found out.
  • "Hungarian notation" and similar styles should not be used since they are confusing and dangerous.

You instinct of using hash_entry* instead is sound.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Lundin