Knowledge

Void type

Source ๐Ÿ“

165:(which is sometimes confusingly called the "void type"). Unlike a real unit type which is a singleton, the void type lacks a way to represent its value and the language does not provide any way to declare an object or represent a value with type 184:
had the feature, now seen as an annoyance, of generating a warning on any function call that did not use the function's returned value. Old code sometimes
425: 400: 192:
began his work on C++ in 1979โ€“1980, void and void pointers were part of the C language dialect supported by AT&T-derived compilers.
577: 176:
and functions with no arguments simply had empty argument lists. Pointers to untyped data were declared as integers or pointers to
66:, such as performing some task or writing to their output parameters. The usage of the void type in such context is comparable to 948: 582: 572: 567: 320: 351: 555: 456: 20: 133:
functions. The C language standard does not guarantee that the different pointer types have the same size or alignment.
129:) to a pointer to void and back to the original type without losing information, which makes these pointers useful for 39: 733: 146: 87: 706: 282: 130: 823: 628: 560: 522: 285: 110: 63: 19:
This article is about the void type in computer programming languages. For the concept of a void pointer, see
327:. Association for Computing Machinery, Inc. via the author and Lucent Technologies Inc. 1996. Archived from 723: 653: 501: 295:. A function into the void type does not return results, and a side-effectful program with type signature 67: 62:
normally, but does not provide a result value to its caller. Usually such functions are called for their
978: 613: 71: 55: 255:
The C syntax to declare a (non-variadic) function with an as-yet-unspecified number of parameters, e.g.
601: 911: 863: 775: 753: 748: 676: 542: 496: 264: 1009: 785: 449: 141:
A function with void result type ends either by reaching the end of the function or by executing a
938: 853: 267:(and C++), a function prototype with empty parentheses declares a function with zero parameters. 153:
to indicate that the function takes no arguments. Note that in all of these situations, void is
681: 537: 491: 172:
In the earliest versions of C, functions with no specific result defaulted to a return type of
43: 91: 671: 646: 417: 389: 157:
a type qualifier on any value. Despite the name, this is semantically similar to an implicit
28: 1004: 473: 390:"WG14-N2432 : Remove support for function definitions with identifier lists proposal" 8: 999: 943: 921: 848: 701: 693: 442: 926: 906: 858: 833: 618: 587: 196: 150: 813: 743: 718: 532: 527: 377: 347: 189: 958: 843: 641: 328: 142: 126: 59: 24: 963: 828: 780: 713: 300: 185: 916: 738: 728: 636: 369:
C and C++: Case Studies in Compatibility. Reconcilable differences? You decide
993: 838: 373: 795: 770: 79: 293: 199:
has different semantics in C and C++, as detailed in the following table:
973: 968: 818: 765: 592: 162: 75: 51: 878: 873: 790: 758: 663: 606: 289: 276: 953: 931: 883: 550: 506: 465: 158: 83: 868: 368: 188:
such function calls to void to suppress this warning. By the time
181: 122: 47: 125:. A program can convert a pointer to any type of data (except a 109:), but this is an unrelated notion. Variables of this type are 16:
Return type for functions that do not output values when called
418:"WG14-N2841 : No function declarators without prototypes" 434: 98: 299:
does not terminate, or crashes. In particular, there are no
486: 145:
with no returned value. The void type may also replace the
481: 260: 195:
The explicit use of void vs. giving no arguments in a
245:
template <typename... Ts> void f(Ts... ts) {}
239:accepts a constant but unknown number of arguments 991: 21:Pointer (computer programming) ยง C and C++ 344:Programming: Principles and Practice Using C++ 117:type, so in this context (but not the others) 450: 457: 443: 341: 428:from the original on November 12, 2022. 406:from the original on December 27, 2022. 346:. Boston: Addison-Wesley. p. 996. 318: 23:. For types of astronomical voids, see 992: 74:and syntactic constructs which define 438: 410: 382: 13: 92:Unit type#In programming languages 14: 1021: 323:The Development of the C Language 121:acts roughly like a universal or 88:functional programming languages 283:functional programming language 136: 464: 360: 335: 312: 281:Quite contrary to C++, in the 1: 523:Arbitrary-precision or bignum 306: 270: 40:several programming languages 82:. It is also similar to the 7: 342:Stroustrup, Bjarne (2009). 319:Ritchie, Dennis M. (1993). 292:, which has no inhabitants 201: 10: 1026: 288:the void type denotes the 274: 248:(not strictly equivalent) 18: 897: 864:Strongly typed identifier 806: 692: 662: 627: 515: 472: 259:above, was deprecated in 939:Parametric polymorphism 399:. September 25, 2019. 376:, September 01, 2002; 90:and type theory. See 27:. For other uses, see 29:Void (disambiguation) 303:into the void type. 103:pointer to void type 944:Primitive data type 849:Recursive data type 702:Algebraic data type 578:Quadruple precision 366:Bjarne Stroustrup, 907:Abstract data type 588:Extended precision 547:Reduced precision 197:function prototype 151:function prototype 94:for a comparison. 987: 986: 719:Associative array 583:Octuple precision 353:978-0-321-54372-1 253: 252: 190:Bjarne Stroustrup 101:also support the 1017: 959:Type constructor 844:Opaque data type 776:Record or Struct 573:Double precision 568:Single precision 459: 452: 445: 436: 435: 430: 429: 414: 408: 407: 405: 394: 386: 380: 364: 358: 357: 339: 333: 332: 316: 298: 258: 246: 236: 229: 220: 215: 202: 179: 175: 168: 161:, not a zero or 143:return statement 127:function pointer 120: 108: 25:Void (astronomy) 1025: 1024: 1020: 1019: 1018: 1016: 1015: 1014: 1010:Unknown content 990: 989: 988: 983: 964:Type conversion 899: 893: 829:Enumerated type 802: 688: 682:null-terminated 658: 623: 511: 468: 463: 433: 416: 415: 411: 403: 392: 388: 387: 383: 365: 361: 354: 340: 336: 317: 313: 309: 301:total functions 296: 279: 273: 256: 244: 234: 227: 226: 218: 213: 208:C++ equivalent 180:. Some early C 177: 173: 166: 139: 118: 106: 32: 17: 12: 11: 5: 1023: 1013: 1012: 1007: 1002: 985: 984: 982: 981: 976: 971: 966: 961: 956: 951: 946: 941: 936: 935: 934: 924: 919: 917:Data structure 914: 909: 903: 901: 895: 894: 892: 891: 886: 881: 876: 871: 866: 861: 856: 851: 846: 841: 836: 831: 826: 821: 816: 810: 808: 804: 803: 801: 800: 799: 798: 788: 783: 778: 773: 768: 763: 762: 761: 751: 746: 741: 736: 731: 726: 721: 716: 711: 710: 709: 698: 696: 690: 689: 687: 686: 685: 684: 674: 668: 666: 660: 659: 657: 656: 651: 650: 649: 644: 633: 631: 625: 624: 622: 621: 616: 611: 610: 609: 599: 598: 597: 596: 595: 585: 580: 575: 570: 565: 564: 563: 558: 556:Half precision 553: 543:Floating point 540: 535: 530: 525: 519: 517: 513: 512: 510: 509: 504: 499: 494: 489: 484: 478: 476: 470: 469: 462: 461: 454: 447: 439: 432: 431: 424:. 2021-10-10. 409: 381: 359: 352: 334: 331:on 1998-02-20. 310: 308: 305: 275:Main article: 272: 269: 251: 250: 242: 231: 230: 216: 210: 209: 206: 138: 135: 113:to data of an 105:(specified as 15: 9: 6: 4: 3: 2: 1022: 1011: 1008: 1006: 1003: 1001: 998: 997: 995: 980: 977: 975: 972: 970: 967: 965: 962: 960: 957: 955: 952: 950: 947: 945: 942: 940: 937: 933: 930: 929: 928: 925: 923: 920: 918: 915: 913: 910: 908: 905: 904: 902: 896: 890: 887: 885: 882: 880: 877: 875: 872: 870: 867: 865: 862: 860: 857: 855: 852: 850: 847: 845: 842: 840: 839:Function type 837: 835: 832: 830: 827: 825: 822: 820: 817: 815: 812: 811: 809: 805: 797: 794: 793: 792: 789: 787: 784: 782: 779: 777: 774: 772: 769: 767: 764: 760: 757: 756: 755: 752: 750: 747: 745: 742: 740: 737: 735: 732: 730: 727: 725: 722: 720: 717: 715: 712: 708: 705: 704: 703: 700: 699: 697: 695: 691: 683: 680: 679: 678: 675: 673: 670: 669: 667: 665: 661: 655: 652: 648: 645: 643: 640: 639: 638: 635: 634: 632: 630: 626: 620: 617: 615: 612: 608: 605: 604: 603: 600: 594: 591: 590: 589: 586: 584: 581: 579: 576: 574: 571: 569: 566: 562: 559: 557: 554: 552: 549: 548: 546: 545: 544: 541: 539: 536: 534: 531: 529: 526: 524: 521: 520: 518: 514: 508: 505: 503: 500: 498: 495: 493: 490: 488: 485: 483: 480: 479: 477: 475: 474:Uninterpreted 471: 467: 460: 455: 453: 448: 446: 441: 440: 437: 427: 423: 419: 413: 402: 398: 391: 385: 379: 378:print version 375: 371: 370: 363: 355: 349: 345: 338: 330: 326: 324: 315: 311: 304: 302: 294: 291: 287: 284: 278: 268: 266: 262: 249: 243: 240: 233: 232: 228:void f(void); 224: 217: 214:void f(void); 212: 211: 207: 204: 203: 200: 198: 193: 191: 187: 183: 170: 164: 160: 156: 152: 148: 147:argument list 144: 134: 132: 128: 124: 116: 112: 104: 100: 95: 93: 89: 85: 81: 77: 73: 69: 65: 61: 57: 53: 49: 45: 42:derived from 41: 37: 30: 26: 22: 888: 744:Intersection 422:open-std.org 421: 412: 397:open-std.org 396: 384: 367: 362: 343: 337: 329:the original 322: 314: 280: 254: 247: 238: 222: 194: 171: 154: 140: 137:In C and C++ 114: 102: 96: 80:Visual Basic 64:side effects 35: 33: 1005:Type theory 974:Type theory 969:Type system 819:Bottom type 766:Option type 707:generalized 593:Long double 538:Fixed point 163:bottom type 131:polymorphic 115:unspecified 76:subroutines 52:return type 1000:Data types 994:Categories 879:Empty type 874:Type class 824:Collection 781:Refinement 759:metaobject 607:signedness 466:Data types 374:Dr. Dobb's 307:References 290:empty type 277:Empty type 271:In Haskell 68:procedures 954:Subtyping 949:Interface 932:metaclass 884:Unit type 854:Semaphore 834:Exception 739:Inductive 729:Dependent 694:Composite 672:Character 654:Reference 551:Minifloat 507:Bit array 235:void f(); 223:preferred 219:void f(); 182:compilers 159:unit type 84:unit type 50:, is the 36:void type 979:Variable 869:Top type 734:Equality 642:physical 619:Rational 614:Interval 561:bfloat16 426:Archived 401:Archived 257:void f() 123:top type 111:pointers 86:used in 56:function 922:Generic 898:Related 814:Boolean 771:Product 647:virtual 637:Address 629:Pointer 602:Integer 533:Decimal 528:Complex 516:Numeric 297:IO Void 286:Haskell 60:returns 48:Algol68 912:Boxing 900:topics 859:Stream 796:tagged 754:Object 677:String 350:  119:void * 107:void * 97:C and 72:Pascal 807:Other 791:Union 724:Class 714:Array 497:Tryte 404:(PDF) 393:(PDF) 263:. In 186:casts 149:of a 58:that 54:of a 38:, in 927:Kind 889:Void 749:List 664:Text 502:Word 492:Trit 487:Byte 348:ISBN 178:char 167:void 46:and 34:The 786:Set 482:Bit 265:C23 261:C99 174:int 155:not 99:C++ 78:in 70:in 996:: 420:. 395:. 372:, 241:) 205:C 169:. 458:e 451:t 444:v 356:. 325:" 321:" 237:( 225:) 221:( 44:C 31:.

Index

Pointer (computer programming) ยง C and C++
Void (astronomy)
Void (disambiguation)
several programming languages
C
Algol68
return type
function
returns
side effects
procedures
Pascal
subroutines
Visual Basic
unit type
functional programming languages
Unit type#In programming languages
C++
pointers
top type
function pointer
polymorphic
return statement
argument list
function prototype
unit type
bottom type
compilers
casts
Bjarne Stroustrup

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

โ†‘