0

I'm trying to create this structure in Golang -

typedef struct FILE_ID_DESCRIPTOR {
  DWORD        dwSize;
  FILE_ID_TYPE Type;
  union {
    LARGE_INTEGER FileId;
    GUID          ObjectId;
    FILE_ID_128   ExtendedFileId;
  } DUMMYUNIONNAME;
} FILE_ID_DESCRIPTOR, *LPFILE_ID_DESCRIPTOR;

As you can see, this depends on union of three in which unknown is FILE_ID_128 and another structure called FILE_ID_TYPE so I stumbled upon this, which is FILE_ID_128s and the _FILE_ID_TYPE structure is here and here

typedef enum _FILE_ID_TYPE {
  FileIdType,
  ObjectIdType,
  ExtendedFileIdType,
  MaximumFileIdType
} FILE_ID_TYPE, *PFILE_ID_TYPE;

And doing after doing some research, I found out that enum is const in Go but in Go, we can not have a named const so maybe a struct(?) and union are byte slices. But I could not find what MaximumFileIdType meant and how to implement that in Go. Thanks in advance.

Also, reference that I am following.

P.S. - Do let me know the question is down-voted. Do you see lack of efforts? Or is not clear? It'll help making a clearer question

Sushant
  • 3,229
  • 3
  • 15
  • 32
  • What do you mean "we cannot have a named const"? – Flimzy Dec 13 '18 at 09:29
  • What is mean is enums are named in the link that I've provided and used in a different structures but in Go, consts are plain `const (somevar = 1)` – Sushant Dec 13 '18 at 09:30
  • In your example, the name of your const is `somevar`. – Flimzy Dec 13 '18 at 09:53
  • No, what I mean is, for example in C, we define `typedef enum _FILE_ID_TYPE` and use `_FILE_ID_TYPE` in struct `FILE_ID_DESCRIPTOR ` but in Golang, we just say `const (somevar = 1)`, so how do I implement `_FILE_ID_TYPE `? I have posted another link in the answer regarding `FILE_ID_DESCRIPTOR ` – Sushant Dec 13 '18 at 09:59
  • So you mean that Go doesn't support enums, not that it doesn't support named constants? – Flimzy Dec 13 '18 at 10:01
  • Yes, go does not support enums. But I found out enums in C are but consts in Go. Then how do I implement `enum _FILE_ID_TYPE` in Go? – Sushant Dec 13 '18 at 10:02
  • I'm sorry I did not get that @AlexF – Sushant Dec 13 '18 at 10:10
  • 1
    @ThatBird, [`enum`s in C use `int` as their underlying type](https://en.cppreference.com/w/c/language/enum), and have no magic in them: an enum value may be used whereever a plain constant or a value (both of type `int` may be used). Enums have integer values—assigned either automatically (0, 1, …) or manually, and so to emulate a C's enum in Go, you should to two steps: 1) figure out what is the size of `int` in C on your target platform; 2) use one of `intXY` types on your Go side so that its size matches that found on step (1). – kostix Dec 13 '18 at 10:48
  • I always found enums to be a painful and bizarre practice in programming and I am baffled by the many questions from programmers coming from other languages to Go trying to reintroduce them – Vorsprung Dec 13 '18 at 11:25
  • @ThatBird, as to "idiomatic enums", yes, there exist typed constants; you can do something like `const ( foo = int(0); bar = int(1); )` and so on. – kostix Dec 13 '18 at 11:26

0 Answers0