[comp.lang.c++] Naming nested declarations

jordan@aerospace.aero.org (Larry M. Jordan) (01/29/91)

Given the following declaration:

  struct NODE;
  typedef NODE *LVAL;

  struct NODE {
    char n_type;
    char n_flags;
    union ninfo {
      struct cons {
        LVAL xl_car;
        LVAL xl_cdr;
      } n_cons;
      struct vector {
	unsigned length;
	LVAL *xv_data;
      } n_vector;
      ...
    } n_info;
  };

which of the following is "correct":

  [1] int i = sizeof(NODE::ninfo);

  [2] int i = sizeof(union ninfo);

?

Well, Zortech v2.1 can handle [2], but produces an error for [1].
While another vendor can handle [1], but chokes on [2].  Whose right?
What does the ARM say?

Reid Ellis <rae@gpu.utcs.toronto.edu> (01/30/91)

In <98561@aerospace.AERO.ORG> jordan@aerospace.aero.org (Larry M. Jordan) writes:
>  struct NODE {
>    ...
>    union ninfo {
>      ...
>    } n_info;
>  };
>
>which of the following is "correct"?
>
>  [1] int i = sizeof(NODE::ninfo);
>
>  [2] int i = sizeof(union ninfo);

Well, ARM says [1] is correct, but not a lot of compilers have
implemented nested types yet, so you'd be taking your chances to use
them right now.  You might be best off for now using an #ifdef like

#ifdef OLD_cplusplus
	int i = sizeof(ninfo);	// you don't need an explicit "union",
				// do you?
#else
	int i = sizeof(NODE::ninfo);
#endif

					Reid
--
Reid Ellis  176 Brookbanks Drive, Toronto ON, M3A 2T5 Canada
rae@gpu.utcs.toronto.edu      ||  rae%alias@csri.toronto.edu
CDA0610@applelink.apple.com   ||             +1 416 446 1644