请输入您要查询的百科知识:

 

词条 Tag (programming)
释义

  1. In AmigaOS

     Example  Implementation 

  2. In general

  3. See also

  4. References

  5. External links

{{other uses|Tag (disambiguation){{!}}Tag#Computing}}{{refimprove|date=November 2016}}

In programming, a tag is an argument to a subroutine that determines other arguments passed to it, which is used as a way to pass indefinite number of tagged parameters to the subroutine; notably, tags are used for a number of system calls in AmigaOS v2.0 and onwards.

In AmigaOS

In earlier versions of AmigaOS, if a system call required setting a large number of parameters, instead of passing them as function arguments, the function would require a pointer to a structure that holds the arguments (for example, intuition.library's OpenWindow() required struct NewWindow with 17 different parameters). Tags were introduced in AmigaOS 2.0 because they "make it possible to add new parameters to system functions without interfering with the original parameters. They also make specifying parameter lists much clearer and easier."[1]

A number of third-party software libraries for AmigaOS also use tags extensively.

Example

AmigaOS 1.3AmigaOS 2.0+

struct Window *wnd;

struct NewWindow nw = {

        10, 10,        100, 100,        0, 1,        IDCMP_CLOSEWINDOW,                WFLG_SIZEGADGET |                 WFLG_DRAGBAR |                WFLG_DEPTHGADGET |                WFLG_CLOSEGADGET |                WFLG_ACTIVATE,        NULL, NULL,        "WikiWindow",        NULL, NULL,        0, 0,        640, 400,        WBENCHSCREEN

};

wnd = OpenWindow(&nw);

struct Window *wnd;

wnd = OpenWindowTags(NULL,

        WA_Left, 10, WA_Top, 10,        WA_Width, 100, WA_Height, 100,        WA_IDCMP, IDCMP_CLOSEWINDOW,        WA_Flags,                WFLG_SIZEGADGET |                WFLG_DRAGBAR |                WFLG_DEPTHGADGET |                WFLG_CLOSEGADGET |                WFLG_ACTIVATE,        WA_Title, "WikiWindow",        WA_PubScreenName, "Workbench",        TAG_DONE );

Note how the code without tags is obscure (for example, 0, 1 define window colors) while the code with tags is self-documenting. Note also that fewer parameters have to be defined with tags than are in the structure, as OpenWindowTags will fall back to default parameters.

Implementation

{{Expand section|date=October 2008}}

AmigaOS provides functions for tag handling in its utility.library.

In general

An advantage of tags is that they ease the work with default arguments since the programmer doesn't have to specify them or their substitutes. From this follows another advantage, ease of achieving of both forward and backward compatibility with external libraries: a program written for an older version of the library will work with a newer one, since the newer library will simply set all the parameters not provided by the program to their default values; and a program written for a newer version of the library will still work with the older version, since the older library will simply pay no attention to the newly introduced tags.

A disadvantage of tags is that their processing is slower than simply reading data from a structure or the stack. Additionally, compile time type checking is lost.

See also

{{Portal|Amiga}}
  • Named parameter

References

1. ^{{cite book|title=Amiga ROM Kernal Reference Manual: Libraries|edition=3rd|ISBN=0-201-56774-1|url=http://cataclysm.cx/random/amiga/reference/Libraries_Manual_guide/node0496.html|pages=867}}

External links

  • utility.library autodoc
  • Amiga ROM Kernal Reference Manual: Libraries - Tag index
{{AmigaOS}}

2 : AmigaOS|MorphOS

随便看

 

开放百科全书收录14589846条英语、德语、日语等多语种百科知识,基本涵盖了大多数领域的百科知识,是一部内容自由、开放的电子版国际百科全书。

 

Copyright © 2023 OENC.NET All Rights Reserved
京ICP备2021023879号 更新时间:2024/9/22 17:20:05