N_TAGS

Syntax | Return Value | Arguments | Keywords | Examples | Version History | See Also

The N_TAGS function returns the number of structure tags contained in a structure expression.

Syntax

Result = N_TAGS( Expression [, /DATA_LENGTH] [, /LENGTH] )

Return Value

Returns the number of structure tags and optionally returns the size, in bytes, of the structure.

Arguments

Expression

The expression for which the number of structure tags is to be returned. Expressions that are not of structure type are considered to have no tags. N_TAGS does not search for tags recursively, so if Expression is a structure containing nested structures, only the number of tags in the outermost structure are counted.

Keywords

DATA_LENGTH

Set this keyword to return the total length of all the data fields contained within the structure, in bytes. This differs from LENGTH in that it does not include any alignment padding required by the structure.

The length of the data for a given structure will be the same on any system, as long as the data does not contain strings.

If a data field contains a string, the DATA_LENGTH keyword returns the length of the string's internal descriptor, rather than the length of the string data. (In IDL, strings are represented internally using a descriptor structure that contains information about the string, including its length and a pointer to the string data.) This means that on a given machine, the DATA_LENGTH keyword will report the same length value for all fields containing string data, regardless of the contents of the strings.

Note
The length of a string descriptor can vary between machines, and also between 32-bit and 64-bit versions of IDL. Length differences are caused by differences in structure alignment rules or the size of a machine pointer on the system, and are fundamental properties of the underlying system.

LENGTH

Set this keyword to return the length of the structure, in bytes.

Note
The length of a structure is machine dependent. The length of a given structure will vary depending upon the host machine. IDL pads and aligns structures in a manner consistent with the host machine's C compiler.

Examples

Find the number of tags in the system variable !P and print the result by entering:

PRINT, N_TAGS(!P)

Find the length of !P, in bytes:

PRINT, N_TAGS(!P, /LENGTH)

Version History

Original

Introduced

See Also

CREATE_STRUCT, N_ELEMENTS, TAG_NAMES, Structures (Application Programming)