NO

Author Topic: Simplify structure declaration, why not?  (Read 3409 times)

koluibuoc

  • Guest
Simplify structure declaration, why not?
« on: June 05, 2009, 01:53:54 AM »
Hello Pelles

First, I want to send my thanks to you, Pelles. I really like PellesC!
You have done the great work.

Second, I hope some days in the future PellesC will accept this:

struct Node
{
   int data;
   Node *left;
   Node *right;
}

void main()
{
   Node node;
   ....
}

Because i find structure declaration so confusing and not easy to remember. And I'm lazy to type much. :)

That all.

Hope final PellesC 6.0 will be out soon.

Have a nice day!

Online AlexN

  • Global Moderator
  • Member
  • *****
  • Posts: 394
    • Alex's Link Sammlung
Re: Simplify structure declaration, why not?
« Reply #1 on: June 05, 2009, 07:02:33 AM »
struct Node
{
   int data;
   Node *left;
   Node *right;
}

void main()
{
   Node node;
   ....
}

Because i find structure declaration so confusing and not easy to remember. And I'm lazy to type much. :)
Pelles C can not translate your code exactly, but this can be translated:
Code: [Select]
#include <stdio.h>

#define Node struct _NODE

Node
{
   int data;
   Node *left;
   Node *right;
};

int main()
{
   Node node;
   node.left = NULL;
   node.right = NULL;
   node.data = 0;

   return node.data;
}
I am sure that this is a good solution, but it is near of that what you want. ;)
best regards
 Alex ;)

Romashka

  • Guest
Re: Simplify structure declaration, why not?
« Reply #2 on: June 05, 2009, 05:26:41 PM »
The following code works with /Ze option:
Code: [Select]
typedef struct node node;

typedef struct node {
    node *prev;
    node *next;
    void *value;
} node;

JohnF

  • Guest
Re: Simplify structure declaration, why not?
« Reply #3 on: June 05, 2009, 08:45:48 PM »
Or like this.

Code: [Select]
typedef struct node NODE;

struct node{
    NODE *prev;
    NODE *next;
    void *value;
};

int main(void)
{
NODE node;


John