1 <!-- Copyright (C) 2003 Red Hat, Inc. -->
2 <!-- This material may be distributed only subject to the terms -->
3 <!-- and conditions set forth in the Open Publication License, v1.0 -->
4 <!-- or later (the latest version is presently available at -->
5 <!-- http://www.opencontent.org/openpub/). -->
6 <!-- Distribution of the work or derivative of the work in any -->
7 <!-- standard (paper) book form is prohibited unless prior -->
8 <!-- permission is obtained from the copyright holder. -->
12 >C library startup</TITLE
13 ><meta name="MSSmartTagsPreventParsing" content="TRUE">
16 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
19 TITLE="eCos Reference Manual"
20 HREF="ecos-ref.html"><LINK
22 TITLE="C and math library overview"
23 HREF="c-and-math-library-overview.html"><LINK
26 HREF="libc-thread-safety.html"><LINK
28 TITLE="I/O Package (Device Drivers)"
40 SUMMARY="Header navigation table"
49 >eCos Reference Manual</TH
57 HREF="libc-thread-safety.html"
65 >Chapter 13. C and math library overview</TD
85 NAME="C-LIBRARY-STARTUP">C library startup</H1
87 >The C library includes a function declared as:</P
95 CLASS="PROGRAMLISTING"
104 >This function is used to start an environment in which an
105 ISO C style program can run in the most compatible way.</P
107 >What this function does is to create a thread which will invoke <TT
111 considered a program's entry point. In particular, it can
112 supply arguments to <TT
115 > using the CYGDAT_LIBC_ARGUMENTS
116 configuration option, and when returning from <TT
123 >, pending stdio file output
124 is flushed and any functions registered with <TT
128 invoked. This is all compliant with the ISO C standard in this respect. </P
130 >This thread starts execution when the <SPAN
137 is started. If the <SPAN
143 > kernel package is not
144 available (and hence there is no scheduler), then <TT
146 >cyg_iso_c_start()</TT
151 > function directly, i.e.
152 it will not return until the <TT
161 > function should be defined
162 as the following, and if defined in a C++ file,
163 should have “C” linkage: </P
171 CLASS="PROGRAMLISTING"
194 >The thread that is started by <TT
196 >cyg_iso_c_start()</TT
198 be manipulated directly, if you wish. For example you can suspend
199 it. The kernel C API needs a handle to do this, which is available
200 by including the following in your source code.</P
208 CLASS="PROGRAMLISTING"
209 >extern cyg_handle_t cyg_libc_main_thread;</PRE
214 >Then for example, you can suspend the thread with the line:</P
222 CLASS="PROGRAMLISTING"
223 >cyg_thread_suspend( cyg_libc_main_thread );</PRE
230 >cyg_iso_c_start()</TT
232 do not provide your own <TT
236 the system will provide a <TT
240 which will simply return immediately.</P
242 >In the default configuration, <TT
244 >cyg_iso_c_start()</TT
246 invoked automatically by the <TT
248 >cyg_package_start()</TT
250 in the infrastructure configuration. This means that in the simplest
251 case, your program can indeed consist of simply:</P
259 CLASS="PROGRAMLISTING"
260 >int main( int argc, char *argv[] )
262 printf("Hello eCos\n");
270 >cyg_package_start()</TT
275 or disable the infrastructure configuration option CYGSEM_START_ISO_C_COMPATIBILITY
276 then you must ensure that you call <TT
278 >cyg_iso_c_start()</TT
280 if you want to be able to have your program start at the entry point
291 SUMMARY="Footer navigation table"
302 HREF="libc-thread-safety.html"
336 HREF="c-and-math-library-overview.html"
344 >I/O Package (Device Drivers)</TD