1

enter image description here

can someone explains this to me am just trying to understand how does this works when i print it out i see more than 1 char which is a full string but in reality i don't think that this should work i would like someone to explain this to me and it would be also great if you link a source from where did you get this info thanks. (btw am parsing the import address table)

zeroaceee
  • 79
  • 6
  • 5
    Please don't use images of code, use text instead. As a new user here, also take the [tour] and read [ask]. – Ulrich Eckhardt Jul 19 '20 at 18:32
  • 1
    https://en.cppreference.com/w/cpp/language/ub – Jesper Juhl Jul 19 '20 at 18:34
  • @yaodav most likely has it, Flexible Array Member, in the proposed Duplicate. It's a C programming trick that's not supported in C++. – user4581301 Jul 19 '20 at 18:34
  • 1
    What you see is a way to work around the lack of [*flexible array member*](https://en.wikipedia.org/wiki/Flexible_array_member) in C++. C have had it since the C99 standard, but it was commonly emulated using one-sized arrays like you see. And considering the naming I suspect you're looking at a Windows API structure, and as such might be older than the C99 standard and needed to use such "hacks". I really recommend *against* you trying to use such things in your own C++ code. – Some programmer dude Jul 19 '20 at 18:36
  • @user4581301 it came from the c standart as Some programmer dude wrote – yaodav Jul 19 '20 at 18:40
  • 3
    Line 18000... i can’t even imagine... – henhen Jul 19 '20 at 18:52
  • I cropped your image to remove the line numbers then pasted into my IDE (I wanted to recreate your issue). My IDE doesn't paste images. Please edit your post with the text. Text is a lot easier to paste into IDEs and compile. – Thomas Matthews Jul 19 '20 at 19:08
  • 1
    Since you tagged as C++, you don't need the `typedef struct`. The `typedef struct` is a holdover from the C language. Your example looks more like C language than C++. – Thomas Matthews Jul 19 '20 at 19:09
  • @ThomasMatthews am using c++ the but the struct looked like that when parsing pe headers but anyways (some programmer dude) answered my question thank you everyone and am sorry for using images won't happen again. – zeroaceee Jul 20 '20 at 04:20

1 Answers1

0

In your example, the Name member is a marker for where the end of the structure.

This is a hack in early C language, mostly used with message formats.

+------+------+    
| Hint | Name |  
+------+------+    
       ^      ^  
       |      +----- One end of the "message"  
       |  
       +----- Possible end of the message.  

The Name field may be a variable length amount of text, thus it can't be declared as a true array (arrays have fixed capacities at runtime), so only one character is allocated.

If zero characters were allocated, the compiler may eliminate the Name member because it has no size.

This is not safe coding style.

Thomas Matthews
  • 56,849
  • 17
  • 98
  • 154