NO

Author Topic: Difficult declarations  (Read 7009 times)

JohnF

  • Guest
Difficult declarations
« on: September 22, 2005, 11:10:02 AM »
An interesting code snippet that tells you what a declaration is. For example, many will find the following difficult;

Code: [Select]
char *(*c[10])(int **p);

The program output for the above is

"c is array 0..9 of pointer to function returning pointer to char"

I think the code was by Peter van der Linden

John

Offline jack

  • Member
  • *
  • Posts: 66
Difficult declarations
« Reply #1 on: September 23, 2005, 08:01:19 PM »
Thanks JohnF, I have been looking for a utility that would de-mystify declarations, especially declarations with structures.
Now if you would extend this utility to graphically display variable declarations and structures as a tree-view I would pay for it. :)

JohnF

  • Guest
Difficult declarations
« Reply #2 on: September 23, 2005, 08:44:10 PM »
Quote from: "jack"
Thanks JohnF, I have been looking for a utility that would de-mystify declarations, especially declarations with structures.
Now if you would extend this utility to graphically display variable declarations and structures as a tree-view I would pay for it. :)


Can you give an example?

John

Mikehg

  • Guest
Difficult declarations
« Reply #3 on: September 24, 2005, 03:25:46 PM »
Hi John,

It seems this could be a lot more useful if the data type didn't need to be known.  i.e. it might be written as char* or LPSTR. and of course UDT's.

Thanks,
Mike H.

JohnF

  • Guest
Difficult declarations
« Reply #4 on: September 24, 2005, 03:40:17 PM »
I doubt it would take much to add the extra code to deal with Windows types.

EDIT: Or you could try to do it your way.

John

JohnF

  • Guest
Difficult declarations
« Reply #5 on: September 25, 2005, 10:04:05 AM »
I've made a few changes to this project.

It will deal with a commandline arg, makes it easier for testing and development.

The types are now stored in an array so more types can be added easily as required.

Code: [Select]

char * sTypes[] = {"void",
"char",
"LPSTR",
"LPCSTR",
"signed",
"unsigned",
"short",
"WORD",
"int",
"INT",
"long",
"LONG",
"DWORD",
"float",
"double",
"struct",
"union",
"enum"};  // 18
#define NUMTYPES 18


John