29
7/29/2019 gccgo.pdf http://slidepdf.com/reader/full/gccgopdf 1/29 The GNU Go Compiler For gcc version 4.7.3 (GCC) Ian Lance Taylor

gccgo.pdf

Embed Size (px)

Citation preview

Page 1: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 1/29

The GNU Go CompilerFor gcc version 4.7.3

(GCC)

Ian Lance Taylor

Page 2: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 2/29

Page 3: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 3/29

i

Table of Contents

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

GNU General Public License . . . . . . . . . . . . . . . . . . . . . . 2

GNU Free Documentation License . . . . . . . . . . . . . . . 13

ADDENDUM: How to use this License or your documents . . . . . . . . . 20

1 Invoking gccgo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

2 Import and Export . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

3 C Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3.1 C Type Interoperability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243.2 Function Names. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26

Page 4: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 4/29

Introduction 1

Introduction

This manual describes how to use gccgo, the GNU compiler or the Go programminglanguage. This manual is specically about gccgo. For more inormation about the Goprogramming language in general, including language specications and standard packagedocumentation, see http://golang.org/.

Page 5: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 5/29

GNU General Public License 2

GNU General Public License

Version 3, 29 June 2007

Copyright c 2007 Free Sotware Foundation, Inc. http://fsf.org/

Everyone is permitted to copy and distribute verbatim copies o thislicense document, but changing it is not allowed.

Preamble

The GNU General Public License is a ree, copylet license or sotware and other kinds o works.

The licenses or most sotware and other practical works are designed to take away yourreedom to share and change the works. By contrast, the GNU General Public License isintended to guarantee your reedom to share and change all versions o a program–to make

sure it remains ree sotware or all its users. We, the Free Sotware Foundation, use theGNU General Public License or most o our sotware; it applies also to any other workreleased this way by its authors. You can apply it to your programs, too.

When we speak o ree sotware, we are reerring to reedom, not price. Our GeneralPublic Licenses are designed to make sure that you have the reedom to distribute copieso ree sotware (and charge or them i you wish), that you receive source code or can getit i you want it, that you can change the sotware or use pieces o it in new ree programs,and that you know you can do these things.

To protect your rights, we need to prevent others rom denying you these rights or askingyou to surrender the rights. Thereore, you have certain responsibilities i you distributecopies o the sotware, or i you modiy it: responsibilities to respect the reedom o others.

For example, i you distribute copies o such a program, whether gratis or or a ee, youmust pass on to the recipients the same reedoms that you received. You must make surethat they, too, receive or can get the source code. And you must show them these terms sothey know their rights.

Developers that use the GNU GPL protect your rights with two steps: (1) assert copy-right on the sotware, and (2) ofer you this License giving you legal permission to copy,distribute and/or modiy it.

For the developers’ and authors’ protection, the GPL clearly explains that there is nowarranty or this ree sotware. For both users’ and authors’ sake, the GPL requires thatmodied versions be marked as changed, so that their problems will not be attributederroneously to authors o previous versions.

Some devices are designed to deny users access to install or run modied versions o thesotware inside them, although the manuacturer can do so. This is undamentally incom-patible with the aim o protecting users’ reedom to change the sotware. The systematicpattern o such abuse occurs in the area o products or individuals to use, which is pre-cisely where it is most unacceptable. Thereore, we have designed this version o the GPLto prohibit the practice or those products. I such problems arise substantially in otherdomains, we stand ready to extend this provision to those domains in uture versions o theGPL, as needed to protect the reedom o users.

Page 6: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 6/29

GNU General Public License 3

Finally, every program is threatened constantly by sotware patents. States should notallow patents to restrict development and use o sotware on general-purpose computers, butin those that do, we wish to avoid the special danger that patents applied to a ree programcould make it efectively proprietary. To prevent this, the GPL assures that patents cannotbe used to render the program non-ree.

The precise terms and conditions or copying, distribution and modication ollow.

TERMS AND CONDITIONS

0. Denitions.

“This License” reers to version 3 o the GNU General Public License.

“Copyright” also means copyright-like laws that apply to other kinds o works, such assemiconductor masks.

“The Program” reers to any copyrightable work licensed under this License. Each

licensee is addressed as “you”. “Licensees” and “recipients” may be individuals ororganizations.

To “modiy” a work means to copy rom or adapt all or part o the work in a ashionrequiring copyright permission, other than the making o an exact copy. The resultingwork is called a “modied version” o the earlier work or a work “based on” the earlierwork.

A “covered work” means either the unmodied Program or a work based on the Pro-gram.

To “propagate” a work means to do anything with it that, without permission, wouldmake you directly or secondarily liable or inringement under applicable copyright law,except executing it on a computer or modiying a private copy. Propagation includes

copying, distribution (with or without modication), making available to the public,and in some countries other activities as well.

To “convey” a work means any kind o propagation that enables other parties to makeor receive copies. Mere interaction with a user through a computer network, with notranser o a copy, is not conveying.

An interactive user interace displays “Appropriate Legal Notices” to the extent that itincludes a convenient and prominently visible eature that (1) displays an appropriatecopyright notice, and (2) tells the user that there is no warranty or the work (exceptto the extent that warranties are provided), that licensees may convey the work underthis License, and how to view a copy o this License. I the interace presents a listo user commands or options, such as a menu, a prominent item in the list meets this

criterion.1. Source Code.

The “source code” or a work means the preerred orm o the work or making modi-cations to it. “Object code” means any non-source orm o a work.

A “Standard Interace” means an interace that either is an ocial standard denedby a recognized standards body, or, in the case o interaces specied or a particularprogramming language, one that is widely used among developers working in thatlanguage.

Page 7: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 7/29

GNU General Public License 4

The “System Libraries” o an executable work include anything, other than the work asa whole, that (a) is included in the normal orm o packaging a Major Component, butwhich is not part o that Major Component, and (b) serves only to enable use o thework with that Major Component, or to implement a Standard Interace or which animplementation is available to the public in source code orm. A “Major Component”,in this context, means a major essential component (kernel, window system, and soon) o the specic operating system (i any) on which the executable work runs, or acompiler used to produce the work, or an object code interpreter used to run it.

The “Corresponding Source” or a work in object code orm means all the source codeneeded to generate, install, and (or an executable work) run the object code and tomodiy the work, including scripts to control those activities. However, it does notinclude the work’s System Libraries, or general-purpose tools or generally availableree programs which are used unmodied in perorming those activities but which arenot part o the work. For example, Corresponding Source includes interace denitionles associated with source les or the work, and the source code or shared libraries

and dynamically linked subprograms that the work is specically designed to require,such as by intimate data communication or control ow between those subprogramsand other parts o the work.

The Corresponding Source need not include anything that users can regenerate auto-matically rom other parts o the Corresponding Source.

The Corresponding Source or a work in source code orm is that same work.

2. Basic Permissions.

All rights granted under this License are granted or the term o copyright on theProgram, and are irrevocable provided the stated conditions are met. This License ex-plicitly arms your unlimited permission to run the unmodied Program. The output

rom running a covered work is covered by this License only i the output, given itscontent, constitutes a covered work. This License acknowledges your rights o air useor other equivalent, as provided by copyright law.

You may make, run and propagate covered works that you do not convey, withoutconditions so long as your license otherwise remains in orce. You may convey coveredworks to others or the sole purpose o having them make modications exclusivelyor you, or provide you with acilities or running those works, provided that youcomply with the terms o this License in conveying all material or which you do notcontrol copyright. Those thus making or running the covered works or you must doso exclusively on your behal, under your direction and control, on terms that prohibitthem rom making any copies o your copyrighted material outside their relationshipwith you.

Conveying under any other circumstances is permitted solely under the conditionsstated below. Sublicensing is not allowed; section 10 makes it unnecessary.

3. Protecting Users’ Legal Rights From Anti-Circumvention Law.

No covered work shall be deemed part o an efective technological measure underany applicable law ullling obligations under article 11 o the WIPO copyright treatyadopted on 20 December 1996, or similar laws prohibiting or restricting circumventiono such measures.

Page 8: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 8/29

GNU General Public License 5

When you convey a covered work, you waive any legal power to orbid circumvention o technological measures to the extent such circumvention is efected by exercising rightsunder this License with respect to the covered work, and you disclaim any intentionto limit operation or modication o the work as a means o enorcing, against thework’s users, your or third parties’ legal rights to orbid circumvention o technologicalmeasures.

4. Conveying Verbatim Copies.

You may convey verbatim copies o the Program’s source code as you receive it, in anymedium, provided that you conspicuously and appropriately publish on each copy anappropriate copyright notice; keep intact all notices stating that this License and anynon-permissive terms added in accord with section 7 apply to the code; keep intact allnotices o the absence o any warranty; and give all recipients a copy o this Licensealong with the Program.

You may charge any price or no price or each copy that you convey, and you may ofersupport or warranty protection or a ee.

5. Conveying Modied Source Versions.

You may convey a work based on the Program, or the modications to produce it romthe Program, in the orm o source code under the terms o section 4, provided thatyou also meet all o these conditions:

a. The work must carry prominent notices stating that you modied it, and giving arelevant date.

b. The work must carry prominent notices stating that it is released under this Li-cense and any conditions added under section 7. This requirement modies therequirement in section 4 to “keep intact all notices”.

c. You must license the entire work, as a whole, under this License to anyone who

comes into possession o a copy. This License will thereore apply, along with anyapplicable section 7 additional terms, to the whole o the work, and all its parts,regardless o how they are packaged. This License gives no permission to licensethe work in any other way, but it does not invalidate such permission i you haveseparately received it.

d. I the work has interactive user interaces, each must display Appropriate LegalNotices; however, i the Program has interactive interaces that do not displayAppropriate Legal Notices, your work need not make them do so.

A compilation o a covered work with other separate and independent works, whichare not by their nature extensions o the covered work, and which are not combinedwith it such as to orm a larger program, in or on a volume o a storage or distribution

medium, is called an “aggregate” i the compilation and its resulting copyright arenot used to limit the access or legal rights o the compilation’s users beyond what theindividual works permit. Inclusion o a covered work in an aggregate does not causethis License to apply to the other parts o the aggregate.

6. Conveying Non-Source Forms.

You may convey a covered work in object code orm under the terms o sections 4 and5, provided that you also convey the machine-readable Corresponding Source underthe terms o this License, in one o these ways:

Page 9: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 9/29

GNU General Public License 6

a. Convey the object code in, or embodied in, a physical product (including a phys-ical distribution medium), accompanied by the Corresponding Source xed on adurable physical medium customarily used or sotware interchange.

b. Convey the object code in, or embodied in, a physical product (including a physi-cal distribution medium), accompanied by a written ofer, valid or at least threeyears and valid or as long as you ofer spare parts or customer support or thatproduct model, to give anyone who possesses the object code either (1) a copy o the Corresponding Source or all the sotware in the product that is covered by thisLicense, on a durable physical medium customarily used or sotware interchange,or a price no more than your reasonable cost o physically perorming this con-veying o source, or (2) access to copy the Corresponding Source rom a networkserver at no charge.

c. Convey individual copies o the object code with a copy o the written ofer toprovide the Corresponding Source. This alternative is allowed only occasionallyand noncommercially, and only i you received the object code with such an ofer,

in accord with subsection 6b.

d. Convey the object code by ofering access rom a designated place (gratis or ora charge), and ofer equivalent access to the Corresponding Source in the sameway through the same place at no urther charge. You need not require recipientsto copy the Corresponding Source along with the object code. I the place tocopy the object code is a network server, the Corresponding Source may be ona diferent server (operated by you or a third party) that supports equivalentcopying acilities, provided you maintain clear directions next to the object codesaying where to nd the Corresponding Source. Regardless o what server hoststhe Corresponding Source, you remain obligated to ensure that it is available oras long as needed to satisy these requirements.

e. Convey the object code using peer-to-peer transmission, provided you inorm otherpeers where the object code and Corresponding Source o the work are being oferedto the general public at no charge under subsection 6d.

A separable portion o the object code, whose source code is excluded rom the Cor-responding Source as a System Library, need not be included in conveying the objectcode work.

A “User Product” is either (1) a “consumer product”, which means any tangible per-sonal property which is normally used or personal, amily, or household purposes, or(2) anything designed or sold or incorporation into a dwelling. In determining whethera product is a consumer product, doubtul cases shall be resolved in avor o coverage.For a particular product received by a particular user, “normally used” reers to a

typical or common use o that class o product, regardless o the status o the par-ticular user or o the way in which the particular user actually uses, or expects or isexpected to use, the product. A product is a consumer product regardless o whetherthe product has substantial commercial, industrial or non-consumer uses, unless suchuses represent the only signicant mode o use o the product.

“Installation Inormation” or a User Product means any methods, procedures, autho-rization keys, or other inormation required to install and execute modied versions o acovered work in that User Product rom a modied version o its Corresponding Source.

Page 10: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 10/29

Page 11: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 11/29

GNU General Public License 8

d. Limiting the use or publicity purposes o names o licensors or authors o thematerial; or

e. Declining to grant rights under trademark law or use o some trade names, trade-

marks, or service marks; or. Requiring indemnication o licensors and authors o that material by anyone whoconveys the material (or modied versions o it) with contractual assumptionso liability to the recipient, or any liability that these contractual assumptionsdirectly impose on those licensors and authors.

All other non-permissive additional terms are considered “urther restrictions” withinthe meaning o section 10. I the Program as you received it, or any part o it, con-tains a notice stating that it is governed by this License along with a term that is aurther restriction, you may remove that term. I a license document contains a urtherrestriction but permits relicensing or conveying under this License, you may add to acovered work material governed by the terms o that license document, provided that

the urther restriction does not survive such relicensing or conveying.I you add terms to a covered work in accord with this section, you must place, in therelevant source les, a statement o the additional terms that apply to those les, or anotice indicating where to nd the applicable terms.

Additional terms, permissive or non-permissive, may be stated in the orm o a sep-arately written license, or stated as exceptions; the above requirements apply eitherway.

8. Termination.

You may not propagate or modiy a covered work except as expressly provided un-der this License. Any attempt otherwise to propagate or modiy it is void, and willautomatically terminate your rights under this License (including any patent licenses

granted under the third paragraph o section 11).However, i you cease all violation o this License, then your license rom a particularcopyright holder is reinstated (a) provisionally, unless and until the copyright holderexplicitly and nally terminates your license, and (b) permanently, i the copyrightholder ails to notiy you o the violation by some reasonable means prior to 60 daysater the cessation.

Moreover, your license rom a particular copyright holder is reinstated permanently i the copyright holder noties you o the violation by some reasonable means, this is therst time you have received notice o violation o this License (or any work) rom thatcopyright holder, and you cure the violation prior to 30 days ater your receipt o thenotice.

Termination o your rights under this section does not terminate the licenses o partieswho have received copies or rights rom you under this License. I your rights havebeen terminated and not permanently reinstated, you do not qualiy to receive newlicenses or the same material under section 10.

9. Acceptance Not Required or Having Copies.

You are not required to accept this License in order to receive or run a copy o theProgram. Ancillary propagation o a covered work occurring solely as a consequence o using peer-to-peer transmission to receive a copy likewise does not require acceptance.

Page 12: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 12/29

GNU General Public License 9

However, nothing other than this License grants you permission to propagate or modiyany covered work. These actions inringe copyright i you do not accept this License.Thereore, by modiying or propagating a covered work, you indicate your acceptanceo this License to do so.

10. Automatic Licensing o Downstream Recipients.

Each time you convey a covered work, the recipient automatically receives a licenserom the original licensors, to run, modiy and propagate that work, subject to thisLicense. You are not responsible or enorcing compliance by third parties with thisLicense.

An “entity transaction” is a transaction transerring control o an organization, orsubstantially all assets o one, or subdividing an organization, or merging organizations.I propagation o a covered work results rom an entity transaction, each party to thattransaction who receives a copy o the work also receives whatever licenses to the workthe party’s predecessor in interest had or could give under the previous paragraph, plusa right to possession o the Corresponding Source o the work rom the predecessor in

interest, i the predecessor has it or can get it with reasonable eforts.

You may not impose any urther restrictions on the exercise o the rights granted orarmed under this License. For example, you may not impose a license ee, royalty, orother charge or exercise o rights granted under this License, and you may not initiatelitigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patentclaim is inringed by making, using, selling, ofering or sale, or importing the Programor any portion o it.

11. Patents.

A “contributor” is a copyright holder who authorizes use under this License o theProgram or a work on which the Program is based. The work thus licensed is calledthe contributor’s “contributor version”.

A contributor’s “essential patent claims” are all patent claims owned or controlled bythe contributor, whether already acquired or hereater acquired, that would be inringedby some manner, permitted by this License, o making, using, or selling its contributorversion, but do not include claims that would be inringed only as a consequence o urther modication o the contributor version. For purposes o this denition, “con-trol” includes the right to grant patent sublicenses in a manner consistent with therequirements o this License.

Each contributor grants you a non-exclusive, worldwide, royalty-ree patent licenseunder the contributor’s essential patent claims, to make, use, sell, ofer or sale, importand otherwise run, modiy and propagate the contents o its contributor version.

In the ollowing three paragraphs, a “patent license” is any express agreement or com-

mitment, however denominated, not to enorce a patent (such as an express permissionto practice a patent or covenant not to sue or patent inringement). To “grant” sucha patent license to a party means to make such an agreement or commitment not toenorce a patent against the party.

I you convey a covered work, knowingly relying on a patent license, and the Corre-sponding Source o the work is not available or anyone to copy, ree o charge and underthe terms o this License, through a publicly available network server or other readilyaccessible means, then you must either (1) cause the Corresponding Source to be so

Page 13: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 13/29

GNU General Public License 10

available, or (2) arrange to deprive yoursel o the benet o the patent license or thisparticular work, or (3) arrange, in a manner consistent with the requirements o thisLicense, to extend the patent license to downstream recipients. “Knowingly relying”means you have actual knowledge that, but or the patent license, your conveying thecovered work in a country, or your recipient’s use o the covered work in a country,would inringe one or more identiable patents in that country that you have reasonto believe are valid.

I, pursuant to or in connection with a single transaction or arrangement, you convey,or propagate by procuring conveyance o, a covered work, and grant a patent licenseto some o the parties receiving the covered work authorizing them to use, propagate,modiy or convey a specic copy o the covered work, then the patent license you grantis automatically extended to all recipients o the covered work and works based on it.

A patent license is “discriminatory” i it does not include within the scope o its cover-age, prohibits the exercise o, or is conditioned on the non-exercise o one or more o the

rights that are specically granted under this License. You may not convey a coveredwork i you are a party to an arrangement with a third party that is in the business o distributing sotware, under which you make payment to the third party based on theextent o your activity o conveying the work, and under which the third party grants,to any o the parties who would receive the covered work rom you, a discriminatorypatent license (a) in connection with copies o the covered work conveyed by you (orcopies made rom those copies), or (b) primarily or and in connection with specicproducts or compilations that contain the covered work, unless you entered into thatarrangement, or that patent license was granted, prior to 28 March 2007.

Nothing in this License shall be construed as excluding or limiting any implied license orother deenses to inringement that may otherwise be available to you under applicable

patent law.12. No Surrender o Others’ Freedom.

I conditions are imposed on you (whether by court order, agreement or otherwise) thatcontradict the conditions o this License, they do not excuse you rom the conditionso this License. I you cannot convey a covered work so as to satisy simultaneouslyyour obligations under this License and any other pertinent obligations, then as aconsequence you may not convey it at all. For example, i you agree to terms thatobligate you to collect a royalty or urther conveying rom those to whom you conveythe Program, the only way you could satisy both those terms and this License wouldbe to rerain entirely rom conveying the Program.

13. Use with the GNU Afero General Public License.

Notwithstanding any other provision o this License, you have permission to link orcombine any covered work with a work licensed under version 3 o the GNU AferoGeneral Public License into a single combined work, and to convey the resulting work.The terms o this License will continue to apply to the part which is the covered work,but the special requirements o the GNU Afero General Public License, section 13,concerning interaction through a network will apply to the combination as such.

14. Revised Versions o this License.

Page 14: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 14/29

GNU General Public License 11

The Free Sotware Foundation may publish revised and/or new versions o the GNUGeneral Public License rom time to time. Such new versions will be similar in spiritto the present version, but may difer in detail to address new problems or concerns.

Each version is given a distinguishing version number. I the Program species thata certain numbered version o the GNU General Public License “or any later version”applies to it, you have the option o ollowing the terms and conditions either o thatnumbered version or o any later version published by the Free Sotware Foundation.I the Program does not speciy a version number o the GNU General Public License,you may choose any version ever published by the Free Sotware Foundation.

I the Program species that a proxy can decide which uture versions o the GNUGeneral Public License can be used, that proxy’s public statement o acceptance o aversion permanently authorizes you to choose that version or the Program.

Later license versions may give you additional or diferent permissions. However, noadditional obligations are imposed on any author or copyright holder as a result o your

choosing to ollow a later version.15. Disclaimer o Warranty.

THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PER-MITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED INWRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDETHE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EX-PRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULARPURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCEOF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFEC-TIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR

CORRECTION.16. Limitation o Liability.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO INWRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHOMODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BELIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, IN-CIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE ORINABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TOLOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUS-TAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAMTO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR

OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAM-AGES.

17. Interpretation o Sections 15 and 16.

I the disclaimer o warranty and limitation o liability provided above cannot be givenlocal legal efect according to their terms, reviewing courts shall apply local law thatmost closely approximates an absolute waiver o all civil liability in connection withthe Program, unless a warranty or assumption o liability accompanies a copy o theProgram in return or a ee.

Page 15: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 15/29

GNU General Public License 12

END OF TERMS AND CONDITIONS

How to Apply These Terms to Your New Programs

I you develop a new program, and you want it to be o the greatest possible use to the public,the best way to achieve this is to make it ree sotware which everyone can redistribute andchange under these terms.

To do so, attach the ollowing notices to the program. It is saest to attach them to thestart o each source le to most efectively state the exclusion o warranty; and each leshould have at least the “copyright” line and a pointer to where the ull notice is ound.

one line to give the program’s name and a brief idea of what it does.

Copyright (C) year name of author 

This program is free software: you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation, either version 3 of the License, or (atyour option) any later version.

This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.

You should have received a copy of the GNU General Public License

along with this program. If not, see http://www.gnu.org/licenses/.

Also add inormation on how to contact you by electronic and paper mail.

I the program does terminal interaction, make it output a short notice like this when itstarts in an interactive mode:

 program Copyright (C) year name of author 

This program comes with ABSOLUTELY NO WARRANTY; for details type ‘show w’.This is free software, and you are welcome to redistribute itunder certain conditions; type ‘show c’ for details.

The hypothetical commands ‘show w’ and ‘show c’ should show the appropriate parts o the General Public License. O course, your program’s commands might be diferent; or aGUI interace, you would use an “about box”.

You should also get your employer (i you work as a programmer) or school, i any, tosign a “copyright disclaimer” or the program, i necessary. For more inormation on this,and how to apply and ollow the GNU GPL, see http://www.gnu.org/licenses/.

The GNU General Public License does not permit incorporating your program intoproprietary programs. I your program is a subroutine library, you may consider it moreuseul to permit linking proprietary applications with the library. I this is what you want

to do, use the GNU Lesser General Public License instead o this License. But rst, pleaseread http://www.gnu.org/philosophy/why-not-lgpl.html .

Page 16: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 16/29

GNU Free Documentation License 13

GNU Free Documentation License

Version 1.3, 3 November 2008

Copyright c 2000, 2001, 2002, 2007, 2008 Free Sotware Foundation, Inc.http://fsf.org/

Everyone is permitted to copy and distribute verbatim copieso this license document, but changing it is not allowed.

0. PREAMBLE

The purpose o this License is to make a manual, textbook, or other unctional anduseul document free  in the sense o reedom: to assure everyone the efective reedomto copy and redistribute it, with or without modiying it, either commercially or non-commercially. Secondarily, this License preserves or the author and publisher a wayto get credit or their work, while not being considered responsible or modicationsmade by others.

This License is a kind o “copylet”, which means that derivative works o the documentmust themselves be ree in the same sense. It complements the GNU General PublicLicense, which is a copylet license designed or ree sotware.

We have designed this License in order to use it or manuals or ree sotware, becauseree sotware needs ree documentation: a ree program should come with manualsproviding the same reedoms that the sotware does. But this License is not limited tosotware manuals; it can be used or any textual work, regardless o subject matter orwhether it is published as a printed book. We recommend this License principally orworks whose purpose is instruction or reerence.

1. APPLICABILITY AND DEFINITIONS

This License applies to any manual or other work, in any medium, that contains anotice placed by the copyright holder saying it can be distributed under the termso this License. Such a notice grants a world-wide, royalty-ree license, unlimited induration, to use that work under the conditions stated herein. The “Document”,below, reers to any such manual or work. Any member o the public is a licensee, andis addressed as “you”. You accept the license i you copy, modiy or distribute the workin a way requiring permission under copyright law.

A “Modied Version” o the Document means any work containing the Document ora portion o it, either copied verbatim, or with modications and/or translated intoanother language.

A “Secondary Section” is a named appendix or a ront-matter section o the Documentthat deals exclusively with the relationship o the publishers or authors o the Document

to the Document’s overall subject (or to related matters) and contains nothing thatcould all directly within that overall subject. (Thus, i the Document is in part atextbook o mathematics, a Secondary Section may not explain any mathematics.) Therelationship could be a matter o historical connection with the subject or with relatedmatters, or o legal, commercial, philosophical, ethical or political position regardingthem.

The “Invariant Sections” are certain Secondary Sections whose titles are designated, asbeing those o Invariant Sections, in the notice that says that the Document is released

Page 17: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 17/29

GNU Free Documentation License 14

under this License. I a section does not t the above denition o Secondary then it isnot allowed to be designated as Invariant. The Document may contain zero InvariantSections. I the Document does not identiy any Invariant Sections then there are none.

The “Cover Texts” are certain short passages o text that are listed, as Front-CoverTexts or Back-Cover Texts, in the notice that says that the Document is released underthis License. A Front-Cover Text may be at most 5 words, and a Back-Cover Text maybe at most 25 words.

A “Transparent” copy o the Document means a machine-readable copy, representedin a ormat whose specication is available to the general public, that is suitable orrevising the document straightorwardly with generic text editors or (or images com-posed o pixels) generic paint programs or (or drawings) some widely available drawingeditor, and that is suitable or input to text ormatters or or automatic translation toa variety o ormats suitable or input to text ormatters. A copy made in an otherwiseTransparent le ormat whose markup, or absence o markup, has been arranged tothwart or discourage subsequent modication by readers is not Transparent. An imageormat is not Transparent i used or any substantial amount o text. A copy that isnot “Transparent” is called “Opaque”.

Examples o suitable ormats or Transparent copies include plain ascii withoutmarkup, Texino input ormat, LaTEX input ormat, SGML or XML using a publiclyavailable DTD, and standard-conorming simple HTML, PostScript or PDF designedor human modication. Examples o transparent image ormats include PNG, XCF

and JPG. Opaque ormats include proprietary ormats that can be read and editedonly by proprietary word processors, SGML or XML or which the DTD and/orprocessing tools are not generally available, and the machine-generated HTML,PostScript or PDF produced by some word processors or output purposes only.

The “Title Page” means, or a printed book, the title page itsel, plus such ollowingpages as are needed to hold, legibly, the material this License requires to appear in thetitle page. For works in ormats which do not have any title page as such, “Title Page”means the text near the most prominent appearance o the work’s title, preceding thebeginning o the body o the text.

The “publisher” means any person or entity that distributes copies o the Documentto the public.

A section “Entitled XYZ” means a named subunit o the Document whose title eitheris precisely XYZ or contains XYZ in parentheses ollowing text that translates XYZ inanother language. (Here XYZ stands or a specic section name mentioned below, suchas “Acknowledgements”, “Dedications”, “Endorsements”, or “History”.) To “Preserve

the Title” o such a section when you modiy the Document means that it remains asection “Entitled XYZ” according to this denition.

The Document may include Warranty Disclaimers next to the notice which states thatthis License applies to the Document. These Warranty Disclaimers are considered tobe included by reerence in this License, but only as regards disclaiming warranties:any other implication that these Warranty Disclaimers may have is void and has noefect on the meaning o this License.

2. VERBATIM COPYING

Page 18: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 18/29

GNU Free Documentation License 15

You may copy and distribute the Document in any medium, either commercially ornoncommercially, provided that this License, the copyright notices, and the licensenotice saying this License applies to the Document are reproduced in all copies, andthat you add no other conditions whatsoever to those o this License. You may not usetechnical measures to obstruct or control the reading or urther copying o the copiesyou make or distribute. However, you may accept compensation in exchange or copies.I you distribute a large enough number o copies you must also ollow the conditionsin section 3.

You may also lend copies, under the same conditions stated above, and you may publiclydisplay copies.

3. COPYING IN QUANTITY

I you publish printed copies (or copies in media that commonly have printed covers) o the Document, numbering more than 100, and the Document’s license notice requiresCover Texts, you must enclose the copies in covers that carry, clearly and legibly, allthese Cover Texts: Front-Cover Texts on the ront cover, and Back-Cover Texts onthe back cover. Both covers must also clearly and legibly identiy you as the publishero these copies. The ront cover must present the ull title with all words o the titleequally prominent and visible. You may add other material on the covers in addition.Copying with changes limited to the covers, as long as they preserve the title o theDocument and satisy these conditions, can be treated as verbatim copying in otherrespects.

I the required texts or either cover are too voluminous to t legibly, you should putthe rst ones listed (as many as t reasonably) on the actual cover, and continue therest onto adjacent pages.

I you publish or distribute Opaque copies o the Document numbering more than 100,you must either include a machine-readable Transparent copy along with each Opaque

copy, or state in or with each Opaque copy a computer-network location rom whichthe general network-using public has access to download using public-standard networkprotocols a complete Transparent copy o the Document, ree o added material. I you use the latter option, you must take reasonably prudent steps, when you begindistribution o Opaque copies in quantity, to ensure that this Transparent copy willremain thus accessible at the stated location until at least one year ater the last timeyou distribute an Opaque copy (directly or through your agents or retailers) o thatedition to the public.

It is requested, but not required, that you contact the authors o the Document wellbeore redistributing any large number o copies, to give them a chance to provide youwith an updated version o the Document.

4. MODIFICATIONSYou may copy and distribute a Modied Version o the Document under the conditionso sections 2 and 3 above, provided that you release the Modied Version under preciselythis License, with the Modied Version lling the role o the Document, thus licensingdistribution and modication o the Modied Version to whoever possesses a copy o it. In addition, you must do these things in the Modied Version:

A. Use in the Title Page (and on the covers, i any) a title distinct rom that o theDocument, and rom those o previous versions (which should, i there were any,

Page 19: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 19/29

GNU Free Documentation License 16

be listed in the History section o the Document). You may use the same title asa previous version i the original publisher o that version gives permission.

B. List on the Title Page, as authors, one or more persons or entities responsible or

authorship o the modications in the Modied Version, together with at least veo the principal authors o the Document (all o its principal authors, i it has ewerthan ve), unless they release you rom this requirement.

C. State on the Title page the name o the publisher o the Modied Version, as thepublisher.

D. Preserve all the copyright notices o the Document.

E. Add an appropriate copyright notice or your modications adjacent to the othercopyright notices.

F. Include, immediately ater the copyright notices, a license notice giving the publicpermission to use the Modied Version under the terms o this License, in the ormshown in the Addendum below.

G. Preserve in that license notice the ull lists o Invariant Sections and required CoverTexts given in the Document’s license notice.

H. Include an unaltered copy o this License.

I. Preserve the section Entitled “History”, Preserve its Title, and add to it an itemstating at least the title, year, new authors, and publisher o the Modied Versionas given on the Title Page. I there is no section Entitled “History” in the Docu-ment, create one stating the title, year, authors, and publisher o the Documentas given on its Title Page, then add an item describing the Modied Version asstated in the previous sentence.

J. Preserve the network location, i any, given in the Document or public access toa Transparent copy o the Document, and likewise the network locations given inthe Document or previous versions it was based on. These may be placed in the“History” section. You may omit a network location or a work that was publishedat least our years beore the Document itsel, or i the original publisher o theversion it reers to gives permission.

K. For any section Entitled “Acknowledgements” or “Dedications”, Preserve the Titleo the section, and preserve in the section all the substance and tone o each o thecontributor acknowledgements and/or dedications given therein.

L. Preserve all the Invariant Sections o the Document, unaltered in their text andin their titles. Section numbers or the equivalent are not considered part o thesection titles.

M. Delete any section Entitled “Endorsements”. Such a section may not be includedin the Modied Version.

N. Do not retitle any existing section to be Entitled “Endorsements” or to conict intitle with any Invariant Section.

O. Preserve any Warranty Disclaimers.

I the Modied Version includes new ront-matter sections or appendices that qualiyas Secondary Sections and contain no material copied rom the Document, you may atyour option designate some or all o these sections as invariant. To do this, add their

Page 20: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 20/29

GNU Free Documentation License 17

titles to the list o Invariant Sections in the Modied Version’s license notice. Thesetitles must be distinct rom any other section titles.

You may add a section Entitled “Endorsements”, provided it contains nothing but

endorsements o your Modied Version by various parties—or example, statements o peer review or that the text has been approved by an organization as the authoritativedenition o a standard.

You may add a passage o up to ve words as a Front-Cover Text, and a passage o upto 25 words as a Back-Cover Text, to the end o the list o Cover Texts in the ModiedVersion. Only one passage o Front-Cover Text and one o Back-Cover Text may beadded by (or through arrangements made by) any one entity. I the Document alreadyincludes a cover text or the same cover, previously added by you or by arrangementmade by the same entity you are acting on behal o, you may not add another; butyou may replace the old one, on explicit permission rom the previous publisher thatadded the old one.

The author(s) and publisher(s) o the Document do not by this License give permissionto use their names or publicity or or to assert or imply endorsement o any ModiedVersion.

5. COMBINING DOCUMENTS

You may combine the Document with other documents released under this License,under the terms dened in section 4 above or modied versions, provided that youinclude in the combination all o the Invariant Sections o all o the original documents,unmodied, and list them all as Invariant Sections o your combined work in its licensenotice, and that you preserve all their Warranty Disclaimers.

The combined work need only contain one copy o this License, and multiple identicalInvariant Sections may be replaced with a single copy. I there are multiple Invariant

Sections with the same name but diferent contents, make the title o each such sectionunique by adding at the end o it, in parentheses, the name o the original author orpublisher o that section i known, or else a unique number. Make the same adjustmentto the section titles in the list o Invariant Sections in the license notice o the combinedwork.

In the combination, you must combine any sections Entitled “History” in the vari-ous original documents, orming one section Entitled “History”; likewise combine anysections Entitled “Acknowledgements”, and any sections Entitled “Dedications”. Youmust delete all sections Entitled “Endorsements.”

6. COLLECTIONS OF DOCUMENTS

You may make a collection consisting o the Document and other documents released

under this License, and replace the individual copies o this License in the variousdocuments with a single copy that is included in the collection, provided that youollow the rules o this License or verbatim copying o each o the documents in allother respects.

You may extract a single document rom such a collection, and distribute it individu-ally under this License, provided you insert a copy o this License into the extracteddocument, and ollow this License in all other respects regarding verbatim copying o that document.

Page 21: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 21/29

GNU Free Documentation License 18

7. AGGREGATION WITH INDEPENDENT WORKS

A compilation o the Document or its derivatives with other separate and independentdocuments or works, in or on a volume o a storage or distribution medium, is called

an “aggregate” i the copyright resulting rom the compilation is not used to limit thelegal rights o the compilation’s users beyond what the individual works permit. Whenthe Document is included in an aggregate, this License does not apply to the otherworks in the aggregate which are not themselves derivative works o the Document.

I the Cover Text requirement o section 3 is applicable to these copies o the Document,then i the Document is less than one hal o the entire aggregate, the Document’s CoverTexts may be placed on covers that bracket the Document within the aggregate, or theelectronic equivalent o covers i the Document is in electronic orm. Otherwise theymust appear on printed covers that bracket the whole aggregate.

8. TRANSLATION

Translation is considered a kind o modication, so you may distribute translations

o the Document under the terms o section 4. Replacing Invariant Sections withtranslations requires special permission rom their copyright holders, but you mayinclude translations o some or all Invariant Sections in addition to the original versionso these Invariant Sections. You may include a translation o this License, and all thelicense notices in the Document, and any Warranty Disclaimers, provided that youalso include the original English version o this License and the original versions o those notices and disclaimers. In case o a disagreement between the translation andthe original version o this License or a notice or disclaimer, the original version willprevail.

I a section in the Document is Entitled “Acknowledgements”, “Dedications”, or “His-tory”, the requirement (section 4) to Preserve its Title (section 1) will typically require

changing the actual title.9. TERMINATION

You may not copy, modiy, sublicense, or distribute the Document except as expresslyprovided under this License. Any attempt otherwise to copy, modiy, sublicense, ordistribute it is void, and will automatically terminate your rights under this License.

However, i you cease all violation o this License, then your license rom a particularcopyright holder is reinstated (a) provisionally, unless and until the copyright holderexplicitly and nally terminates your license, and (b) permanently, i the copyrightholder ails to notiy you o the violation by some reasonable means prior to 60 daysater the cessation.

Moreover, your license rom a particular copyright holder is reinstated permanently i 

the copyright holder noties you o the violation by some reasonable means, this is therst time you have received notice o violation o this License (or any work) rom thatcopyright holder, and you cure the violation prior to 30 days ater your receipt o thenotice.

Termination o your rights under this section does not terminate the licenses o partieswho have received copies or rights rom you under this License. I your rights havebeen terminated and not permanently reinstated, receipt o a copy o some or all o thesame material does not give you any rights to use it.

Page 22: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 22/29

GNU Free Documentation License 19

10. FUTURE REVISIONS OF THIS LICENSE

The Free Sotware Foundation may publish new, revised versions o the GNU FreeDocumentation License rom time to time. Such new versions will be similar in spirit

to the present version, but may difer in detail to address new problems or concerns.See http://www.gnu.org/copyleft/.

Each version o the License is given a distinguishing version number. I the Documentspecies that a particular numbered version o this License “or any later version”applies to it, you have the option o ollowing the terms and conditions either o thatspecied version or o any later version that has been published (not as a drat) bythe Free Sotware Foundation. I the Document does not speciy a version number o this License, you may choose any version ever published (not as a drat) by the FreeSotware Foundation. I the Document species that a proxy can decide which utureversions o this License can be used, that proxy’s public statement o acceptance o aversion permanently authorizes you to choose that version or the Document.

11. RELICENSING

“Massive Multiauthor Collaboration Site” (or “MMC Site”) means any World WideWeb server that publishes copyrightable works and also provides prominent acilitiesor anybody to edit those works. A public wiki that anybody can edit is an example o such a server. A “Massive Multiauthor Collaboration” (or “MMC”) contained in thesite means any set o copyrightable works thus published on the MMC site.

“CC-BY-SA” means the Creative Commons Attribution-Share Alike 3.0 license pub-lished by Creative Commons Corporation, a not-or-prot corporation with a principalplace o business in San Francisco, Caliornia, as well as uture copylet versions o thatlicense published by that same organization.

“Incorporate” means to publish or republish a Document, in whole or in part, as parto another Document.

An MMC is “eligible or relicensing” i it is licensed under this License, and i all worksthat were rst published under this License somewhere other than this MMC, andsubsequently incorporated in whole or in part into the MMC, (1) had no cover textsor invariant sections, and (2) were thus incorporated prior to November 1, 2008.

The operator o an MMC Site may republish an MMC contained in the site underCC-BY-SA on the same site at any time beore August 1, 2009, provided the MMC iseligible or relicensing.

Page 23: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 23/29

GNU Free Documentation License 20

ADDENDUM: How to use this License for your documents

To use this License in a document you have written, include a copy o the License in thedocument and put the ollowing copyright and license notices just ater the title page:

Copyright (C) year your name.Permission is granted to copy, distribute and/or modify this documentunder the terms of the GNU Free Documentation License, Version 1.3or any later version published by the Free Software Foundation;with no Invariant Sections, no Front-Cover Texts, and no Back-CoverTexts. A copy of the license is included in the section entitled ‘‘GNU

Free Documentation License’’.

I you have Invariant Sections, Front-Cover Texts and Back-Cover Texts, replace the“with...Texts.” line with this:

with the Invariant Sections being list their titles, withthe Front-Cover Texts being list, and with the Back-Cover Textsbeing list.

I you have Invariant Sections without Cover Texts, or some other combination o the

three, merge those two alternatives to suit the situation.I your document contains nontrivial examples o program code, we recommend releasing

these examples in parallel under your choice o ree sotware license, such as the GNUGeneral Public License, to permit their use in ree sotware.

Page 24: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 24/29

Chapter 1: Invoking gccgo 21

1 Invoking gccgo

The gccgo command is a rontend to gcc and supports many o the same options. SeeSection “Option Summary” in Using the GNU Compiler Collection (GCC). This manualonly documents the options specic to gccgo.

The gccgo command may be used to compile Go source code into an object le, link acollection o object les together, or do both in sequence.

Go source code is compiled as packages. A package consists o one or more Go sourceles. All the les in a single package must be compiled together, by passing all the les asarguments to gccgo. A single invocation o  gccgo may only compile a single package.

One Go package may import a diferent Go package. The imported package must havealready been compiled; gccgo will read the import data directly rom the compiled package.When this package is later linked, the compiled orm o the package must be included inthe link command.

-Idir  Speciy a directory to use when searching or an import package at compiletime.

-Ldir  When linking, speciy a library search directory, as with gcc.

-fgo-pkgpath=string 

Set the package path to use. This sets the value returned by the PkgPathmethod o reect.Type objects. It is also used or the names o globally visiblesymbols. The argument to this option should normally be the string that willbe used to import this package ater it has been installed; in other words, apathname within the directories specied by the ‘-I’ option.

-fgo-prefix=string 

An alternative to ‘-fgo-pkgpath’. The argument will be combined withthe package name rom the source le to produce the package path. I ‘-fgo-pkgpath’ is used, ‘-fgo-prefix’ will be ignored.

Go permits a single program to include more than one package with the samename in the package clause in the source le, though obviously the two pack-ages must be imported using diferent pathnames. In order or this to workwith gccgo, either ‘-fgo-pkgpath’ or ‘-fgo-prefix’ must be specied whencompiling a package.

Using either ‘-fgo-pkgpath’ or ‘-fgo-prefix’ disables the special treatmento the main package and permits that package to be imported like any other.

-fgo-relative-import-path=dir 

A relative import is an import that starts with ‘./’ or ‘../’. I this option isused, gccgo will use dir  as a prex or the relative import when searching orit.

-frequire-return-statement

-fno-require-return-statement

By deault gccgo will warn about unctions which have one or more return pa-rameters but lack an explicit return statement. This warning may be disabledusing ‘-fno-require-return-statement’.

Page 25: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 25/29

Chapter 1: Invoking gccgo 22

-fgo-check-divide-zero

Add explicit checks or division by zero. In Go a division (or modulos) by zerocauses a panic. On Unix systems this is detected in the runtime by catching theSIGFPE signal. Some processors, such as PowerPC, do not generate a SIGFPEon division by zero. Some runtimes do not generate a signal that can be caught.On those systems, this option may be used. Or the checks may be removed via‘-fno-go-check-divide-zero’. This option is currently on by deault, but inthe uture may be of by deault on systems that do not require it.

-fgo-check-divide-overflow

Add explicit checks or division overow. For example, division overow occurswhen computing INT_MIN / -1. In Go this should be wrapped, to produce INT_

MIN. Some processors, such as x86, generate a trap on division overow. Onthose systems, this option may be used. Or the checks may be removed via‘-fno-go-check-divide-overflow’. This option is currently on by deault,but in the uture may be of by deault on systems that do not require it.

Page 26: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 26/29

Chapter 2: Import and Export 23

2 Import and Export

When gccgo compiles a package which exports anything, the export inormation will bestored directly in the object le. When a package is imported, gccgo must be able to ndthe le.

When Go code imports the package ‘gopackage ’, gccgo will look or the import datausing the ollowing lenames, using the rst one that it nds.

‘gopackage.gox’‘libgopackage.so’‘libgopackage.a’‘gopackage.o’

The compiler will search or these les in the directories named by any ‘ -I’ options, inorder in which the directories appear on the command line. The compiler will then searchseveral standard system directories. Finally the compiler will search the current directory

(to search the current directory earlier, use ‘-I.’).The compiler will extract the export inormation directly rom the compiled object le.

The le ‘gopackage.gox’ will typically contain nothing but export data. This can begenerated rom ‘gopackage.o’ via

objcopy -j .go_export gopackage.o gopackage.gox

For example, it may be desirable to extract the export inormation rom several diferentpackages into their independent ‘gopackage.gox’ les, and then to combine the diferentpackage object les together into a single shared library or archive.

At link time you must explicitly tell gccgo which les to link together into the executable,as is usual with gcc. This is diferent rom the behaviour o other Go compilers.

Page 27: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 27/29

Chapter 3: C Interoperability 24

3 C Interoperability

When using gccgo there is limited interoperability with C, or with C++ code compiled using

extern "C".

3.1 C Type Interoperability

Basic types map directly: an int in Go is an int in C, etc. Go byte is equivalent to Cunsigned char. Pointers in Go are pointers in C. A Go struct is the same as C struct

with the same eld names and types.

The Go string type is currently dened as a two-element structure:

struct __go_string {const unsigned char *__data;int __length;

};

You can’t pass arrays between C and Go. However, a pointer to an array in Go isequivalent to a C pointer to the equivalent o the element type. For example, Go *[10]int

is equivalent to C int*, assuming that the C pointer does point to 10 elements.

A slice in Go is a structure. The current denition is:

struct __go_slice {void *__values;int __count;int __capacity;

};

The type o a Go unction with no receiver is equivalent to a C unction whose parameter

types are equivalent. When a Go unction returns more than one value, the C unctionreturns a struct. For example, these unctions have equivalent types:

func GoFunction(int) (int, float)struct { int i; float f; } CFunction(int)

A pointer to a Go unction is equivalent to a pointer to a C unction when the unctionshave equivalent types.

Go interface, channel, and map types have no corresponding C type (interface is atwo-element struct and channel and map are pointers to structs in C, but the structs aredeliberately undocumented). C enum types correspond to some integer type, but preciselywhich one is dicult to predict in general; use a cast. C union types have no correspondingGo type. C struct types containing bitelds have no corresponding Go type. C++ class

types have no corresponding Go type.

Memory allocation is completely diferent between C and Go, as Go uses garbage col-lection. The exact guidelines in this area are undetermined, but it is likely that it willbe permitted to pass a pointer to allocated memory rom C to Go. The responsibility o eventually reeing the pointer will remain with C side, and o course i the C side rees thepointer while the Go side still has a copy the program will ail. When passing a pointer romGo to C, the Go unction must retain a visible copy o it in some Go variable. Otherwisethe Go garbage collector may delete the pointer while the C unction is still using it.

Page 28: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 28/29

Chapter 3: C Interoperability 25

3.2 Function Names

Go code can call C unctions directly using a Go extension implemented in gccgo: a unctiondeclaration may be preceded by a comment giving the external name. The comment must

be at the beginning o the line and must start with //extern. This must be ollowed by aspace and then the external name o the unction. The unction declaration must be on theline immediately ater the comment. For example, here is how the C unction open can bedeclared in Go:

//extern openfunc c_open(name *byte, mode int, perm int) int

The C unction naturally expects a nul terminated string, which in Go is equivalent toa pointer to an array (not a slice!) o  byte with a terminating zero byte. So a sample callrom Go would look like (ater importing the os package):

var name = [4]byte{’f’, ’o’, ’o’, 0};i := c_open(&name[0], os.O_RDONLY, 0);

Note that this serves as an example only. To open a le in Go please use Go’s os.Open

unction instead.

The name o Go unctions accessed rom C is subject to change. At present the name o a Go unction that does not have a receiver is prefix.package.Functionname. The prexis set by the ‘-fgo-prefix’ option used when the package is compiled; i the option is notused, the deault is simply go. To call the unction rom C you must set the name usingthe gcc __asm__ extension.

extern int go_function(int) __asm__ ("myprefix.mypackage.Function");

Page 29: gccgo.pdf

7/29/2019 gccgo.pdf

http://slidepdf.com/reader/full/gccgopdf 29/29

Index 26

Index

-‘-fgo-check-divide-overflow’

. . . . . . . . . . . . . . . .

22

‘-fgo-check-divide-zero’. . . . . . . . . . . . . . . . . . . . . 22

‘-fgo-pkgpath’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

‘-fgo-prefix’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

‘-fgo-relative-import-path’ . . . . . . . . . . . . . . . . . 21

‘-fno-go-check-divide-overflow’ . . . . . . . . . . . . 22

‘-fno-go-check-divide-zero’ . . . . . . . . . . . . . . . . . 22

‘-fno-require-return-statement’ . . . . . . . . . . . . 21

‘-frequire-return-statement’ . . . . . . . . . . . . . . . . 21

‘-I’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

‘-L’ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

.

‘.gox’. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

23

E

extern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

external names . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

F

FDL, GNU Free Documentation License . . . . . . . 13

S

slice in C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

string in C. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

24