diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/SYNTAX |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/SYNTAX')
42 files changed, 5046 insertions, 0 deletions
diff --git a/reference/C/SYNTAX/Makefile.am b/reference/C/SYNTAX/Makefile.am new file mode 100644 index 0000000..9bfe8ac --- /dev/null +++ b/reference/C/SYNTAX/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = $(wildcard *.html) $(wildcard *.c) $(wildcard *.gif) +docs_DATA = $(EXTRA_DIST) + +docsdir = $(kde_htmldir)/en/kdevelop/$(subdir) + diff --git a/reference/C/SYNTAX/Makefile.in b/reference/C/SYNTAX/Makefile.in new file mode 100644 index 0000000..bb58959 --- /dev/null +++ b/reference/C/SYNTAX/Makefile.in @@ -0,0 +1,410 @@ +# KDE tags expanded automatically by am_edit - $Revision: 1.2 $ +# Makefile.in generated automatically by automake 1.5 from Makefile.am. + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = ../../.. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_alias = @build_alias@ +build_triplet = @build@ +host_alias = @host_alias@ +host_triplet = @host@ +target_alias = @target_alias@ +target_triplet = @target@ +AMTAR = @AMTAR@ +ARTSCCONFIG = @ARTSCCONFIG@ +AS = @AS@ +AUTODIRS = @AUTODIRS@ +AWK = @AWK@ +CC = @CC@ +CONF_FILES = @CONF_FILES@ +CPP = @CPP@ +CXX = @CXX@ +CXXCPP = @CXXCPP@ +DCOPIDL = @DCOPIDL@ +DCOPIDL2CPP = @DCOPIDL2CPP@ +DCOP_DEPENDENCIES = @DCOP_DEPENDENCIES@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +DPMSINC = @DPMSINC@ +DPMSLIB = @DPMSLIB@ +EXEEXT = @EXEEXT@ +GCJ = @GCJ@ +GCJFLAGS = @GCJFLAGS@ +GLINC = @GLINC@ +GLLIB = @GLLIB@ +GMSGFMT = @GMSGFMT@ +IDL = @IDL@ +IDL_DEPENDENCIES = @IDL_DEPENDENCIES@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +JAR = @JAR@ +JAVAC = @JAVAC@ +JAVAH = @JAVAH@ +JVMLIBS = @JVMLIBS@ +KDECONFIG = @KDECONFIG@ +KDE_CXXFLAGS = @KDE_CXXFLAGS@ +KDE_EXTRA_RPATH = @KDE_EXTRA_RPATH@ +KDE_INCLUDES = @KDE_INCLUDES@ +KDE_LDFLAGS = @KDE_LDFLAGS@ +KDE_PLUGIN = @KDE_PLUGIN@ +KDE_RPATH = @KDE_RPATH@ +KDE_USE_CLOSURE_FALSE = @KDE_USE_CLOSURE_FALSE@ +KDE_USE_CLOSURE_TRUE = @KDE_USE_CLOSURE_TRUE@ +KDE_USE_FINAL_FALSE = @KDE_USE_FINAL_FALSE@ +KDE_USE_FINAL_TRUE = @KDE_USE_FINAL_TRUE@ +KDE_XSL_STYLESHEET = @KDE_XSL_STYLESHEET@ +LIBCOMPAT = @LIBCOMPAT@ +LIBCRYPT = @LIBCRYPT@ +LIBDL = @LIBDL@ +LIBGEN = @LIBGEN@ +LIBJPEG = @LIBJPEG@ +LIBMICO = @LIBMICO@ +LIBOBJS = @LIBOBJS@ +LIBPNG = @LIBPNG@ +LIBPTHREAD = @LIBPTHREAD@ +LIBPYTHON = @LIBPYTHON@ +LIBQIMGIO = @LIBQIMGIO@ +LIBRESOLV = @LIBRESOLV@ +LIBSHADOW = @LIBSHADOW@ +LIBSM = @LIBSM@ +LIBSOCKET = @LIBSOCKET@ +LIBTIFF = @LIBTIFF@ +LIBTOOL = @LIBTOOL@ +LIBUCB = @LIBUCB@ +LIBUTIL = @LIBUTIL@ +LIBXINERAMA = @LIBXINERAMA@ +LIBZ = @LIBZ@ +LIB_KAB = @LIB_KAB@ +LIB_KDECORE = @LIB_KDECORE@ +LIB_KDEUI = @LIB_KDEUI@ +LIB_KFILE = @LIB_KFILE@ +LIB_KFM = @LIB_KFM@ +LIB_KFORMULA = @LIB_KFORMULA@ +LIB_KHTML = @LIB_KHTML@ +LIB_KIMGIO = @LIB_KIMGIO@ +LIB_KIO = @LIB_KIO@ +LIB_KPARTS = @LIB_KPARTS@ +LIB_KSPELL = @LIB_KSPELL@ +LIB_KSYCOCA = @LIB_KSYCOCA@ +LIB_KWRITE = @LIB_KWRITE@ +LIB_QT = @LIB_QT@ +LIB_SMB = @LIB_SMB@ +LIB_X11 = @LIB_X11@ +LN_S = @LN_S@ +MCOPIDL = @MCOPIDL@ +MEINPROC = @MEINPROC@ +MICO_INCLUDES = @MICO_INCLUDES@ +MICO_LDFLAGS = @MICO_LDFLAGS@ +MOC = @MOC@ +MSGFMT = @MSGFMT@ +NOOPT_CXXFLAGS = @NOOPT_CXXFLAGS@ +NOREPO = @NOREPO@ +OBJDUMP = @OBJDUMP@ +OBJEXT = @OBJEXT@ +PACKAGE = @PACKAGE@ +PAMLIBS = @PAMLIBS@ +PASSWDLIBS = @PASSWDLIBS@ +PYTHONINC = @PYTHONINC@ +PYTHONLIB = @PYTHONLIB@ +PYTHONMODDIR = @PYTHONMODDIR@ +QT_INCLUDES = @QT_INCLUDES@ +QT_LDFLAGS = @QT_LDFLAGS@ +RANLIB = @RANLIB@ +REPO = @REPO@ +SETUIDFLAGS = @SETUIDFLAGS@ +STRIP = @STRIP@ +TOPSUBDIRS = @TOPSUBDIRS@ +UIC = @UIC@ +UIC_TR = @UIC_TR@ +USER_INCLUDES = @USER_INCLUDES@ +USER_LDFLAGS = @USER_LDFLAGS@ +USE_EXCEPTIONS = @USE_EXCEPTIONS@ +USE_RTTI = @USE_RTTI@ +USE_THREADS = @USE_THREADS@ +VERSION = @VERSION@ +XGETTEXT = @XGETTEXT@ +XPMINC = @XPMINC@ +XPMLIB = @XPMLIB@ +X_EXTRA_LIBS = @X_EXTRA_LIBS@ +X_INCLUDES = @X_INCLUDES@ +X_LDFLAGS = @X_LDFLAGS@ +X_PRE_LIBS = @X_PRE_LIBS@ +all_includes = @all_includes@ +all_libraries = @all_libraries@ +am__include = @am__include@ +am__quote = @am__quote@ +idldir = @idldir@ +install_sh = @install_sh@ +jni_includes = @jni_includes@ +kde_appsdir = @kde_appsdir@ +kde_bindir = @kde_bindir@ +kde_confdir = @kde_confdir@ +kde_datadir = @kde_datadir@ +kde_htmldir = @kde_htmldir@ +kde_icondir = @kde_icondir@ +kde_includes = @kde_includes@ +kde_libraries = @kde_libraries@ +kde_libs_htmldir = @kde_libs_htmldir@ +kde_libs_prefix = @kde_libs_prefix@ +kde_locale = @kde_locale@ +kde_mimedir = @kde_mimedir@ +kde_moduledir = @kde_moduledir@ +kde_qtver = @kde_qtver@ +kde_servicesdir = @kde_servicesdir@ +kde_servicetypesdir = @kde_servicetypesdir@ +kde_sounddir = @kde_sounddir@ +kde_templatesdir = @kde_templatesdir@ +kde_wallpaperdir = @kde_wallpaperdir@ +micodir = @micodir@ +qt_includes = @qt_includes@ +qt_libraries = @qt_libraries@ +x_includes = @x_includes@ +x_libraries = @x_libraries@ + +EXTRA_DIST = $(wildcard *.html) $(wildcard *.c) $(wildcard *.gif) +docs_DATA = $(EXTRA_DIST) + +docsdir = $(kde_htmldir)/en/kdevelop/$(subdir) +subdir = reference/C/SYNTAX +mkinstalldirs = $(SHELL) $(top_srcdir)/admin/mkinstalldirs +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +DIST_SOURCES = +DATA = $(docs_DATA) + +DIST_COMMON = Makefile.am Makefile.in +#>- all: all-am +#>+ 1 +all: docs-am all-am + +.SUFFIXES: + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +$(srcdir)/Makefile.in: Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) +#>- cd $(top_srcdir) && \ +#>- $(AUTOMAKE) --gnu reference/C/SYNTAX/Makefile +#>+ 3 + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu reference/C/SYNTAX/Makefile + cd $(top_srcdir) && perl admin/am_edit reference/C/SYNTAX/Makefile.in +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && \ + CONFIG_HEADERS= CONFIG_LINKS= \ + CONFIG_FILES=$(subdir)/$@ $(SHELL) ./config.status +uninstall-info-am: +install-docsDATA: $(docs_DATA) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(docsdir) + @list='$(docs_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(INSTALL_DATA) $$d$$p $(DESTDIR)$(docsdir)/$$f"; \ + $(INSTALL_DATA) $$d$$p $(DESTDIR)$(docsdir)/$$f; \ + done + +uninstall-docsDATA: + @$(NORMAL_UNINSTALL) + @list='$(docs_DATA)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(docsdir)/$$f"; \ + rm -f $(DESTDIR)$(docsdir)/$$f; \ + done +tags: TAGS +TAGS: + + +#>- DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +#>+ 4 +KDE_DIST=if.html static.htm include_preprocessor.html sizeof.html comma.html syntax.gif idioms.html syntax.html conditional.html define_preprocessor.html glo_int_vars.html typedef.html while.html for.html volatile.html break.html return.html comments.html namespace.html syntax_p.html keywords.html functions.html switch.html void.html logical.html goto.html null.html fork1.c struct.html union.html Master.html statements.html enum.html macros.html const.html storage_class.html got_ya.html do.html preprocessors.html continue.html + +DISTFILES= $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) $(KDE_DIST) + + +top_distdir = ../../.. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @for file in $(DISTFILES); do \ + if test -f $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + $(mkinstalldirs) "$(distdir)/$$dir"; \ + fi; \ + if test -d $$d/$$file; then \ + cp -pR $$d/$$file $(distdir) \ + || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(DATA) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(docsdir) + +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) stamp-h stamp-h[0-9]* + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +#>- clean: clean-am +#>+ 1 +clean: kde-rpo-clean clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-generic distclean-libtool + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: install-docsDATA + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +uninstall-am: uninstall-docsDATA uninstall-info-am + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am info info-am install install-am install-data \ + install-data-am install-docsDATA install-exec install-exec-am \ + install-info install-info-am install-man install-strip \ + installcheck installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool uninstall uninstall-am uninstall-docsDATA \ + uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: + +#>+ 2 +docs-am: + +#>+ 6 +force-reedit: + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu reference/C/SYNTAX/Makefile + cd $(top_srcdir) && perl admin/am_edit reference/C/SYNTAX/Makefile.in + + +#>+ 2 +final: + $(MAKE) all-am +#>+ 2 +final-install: + $(MAKE) install-am +#>+ 2 +no-final: + $(MAKE) all-am +#>+ 2 +no-final-install: + $(MAKE) install-am +#>+ 3 +cvs-clean: + $(MAKE) -f $(top_srcdir)/admin/Makefile.common cvs-clean + +#>+ 3 +kde-rpo-clean: + -rm -f *.rpo diff --git a/reference/C/SYNTAX/Master.html b/reference/C/SYNTAX/Master.html new file mode 100644 index 0000000..7e32a47 --- /dev/null +++ b/reference/C/SYNTAX/Master.html @@ -0,0 +1,54 @@ +<title>XXX</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="ffffcc"> +<hr> +<center> +<h1>XXXX</h1> +</center> +<hr> +<b>XXXX</b> +<p> +<hr> +</pre> +<hr> +<h2>Examples:</h2> + +<img src="../../GRAPHICS/computer.gif"><a href="../EXAMPLES/malloc.c"> example</a> +program. + +<hr> +<h2>See Also:</h2> + +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../FUNCTIONS/malloc.html">malloc</a> function.<p> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html diff --git a/reference/C/SYNTAX/break.html b/reference/C/SYNTAX/break.html new file mode 100644 index 0000000..46bbfef --- /dev/null +++ b/reference/C/SYNTAX/break.html @@ -0,0 +1,54 @@ +<title>The break statement</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The break statement.</h1> +</center> +<hr> +<p> +This statement allows the program to escape from <a href=for.html>for</a>, +<a href=while.html>while</a>, +<a href=do.html>do ... while</a> loops and <a href=switch.html>switch</a> structures. +<p> + +It should NOT be used to escape from an <a href=if.html>if</a> block. +<p> + +<hr> +<h2>Examples</h2> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/switch.c"> + Switch example.</a> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html diff --git a/reference/C/SYNTAX/comma.html b/reference/C/SYNTAX/comma.html new file mode 100644 index 0000000..fad68e6 --- /dev/null +++ b/reference/C/SYNTAX/comma.html @@ -0,0 +1,60 @@ +<title>The COMMA.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The COMMA.</h1></center> +<hr> +The comma has two uses. The most comman, is as a parameter seperator +for <a href="../CONCEPT/data_types.html">data types</a> and +<a href="functions.html">function</a> parameter lists. +Here is an example: +<pre> + main() + { + char String1[20], String2[]="Outback Pub"; /* <a href="../CONCEPT/data_types.html">data types</a> */ + strncpy(String1, string2, 7); + } +</pre> +The other use is as a <b>series operator</b> which can be seen in use with +the <a href="for.html">for</a> keyword. An example of the syntax is shown +in the link below. + +<hr> +<h2>Examples:</h2> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/for2.c">Example of the <b>series operator</b></a>. + +<hr> +<h2>See also:</h2> + +Nothing else to see :-( + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html diff --git a/reference/C/SYNTAX/comments.html b/reference/C/SYNTAX/comments.html new file mode 100644 index 0000000..d3ff791 --- /dev/null +++ b/reference/C/SYNTAX/comments.html @@ -0,0 +1,111 @@ +<head> +<title>Comments.</title> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Comments.</h1> +</center> +<hr> +<p> +Lets start with a few examples. +<p> +<center> +<table border=2 width="80%" bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + + int Counter=0; /* Initalise Counter */ + + /* a comment */ + + /* + * Another comment + */ + + /***************** + * + * Final comment. + * + *****************/ + } +</pre> +</td> +</tr> +</table> +</center> +<p> +<hr> +<p> +A comment starts with a <b>/*</b> and +ends with <b>*/</b>. Comments started in this way can span multiple +lines but cannot be nested. +For example: +<p> +<center> +<table border=2 width="80%" bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int Count = 0; /* Initalise + * Counter to 0 */ + + /* /* Invalid comment */ */ + } +</pre> +</td> +</tr> +</table> +</center> +<p> +This will give a syntax error, because the last line +contains nested comments. +<font color=brown> +C++ offers a solution to +<a href="../../CPLUSPLUS/SYNTAX/comment.html">comment nesting.</a> + +<p> +<a name="c++"> +<hr> +<font color=brown> +<h2>C++ Extension</h3> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../../CPLUSPLUS/SYNTAX/comment.html">Inline comments</a> +</font> +<p> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/conditional.html b/reference/C/SYNTAX/conditional.html new file mode 100644 index 0000000..45b39af --- /dev/null +++ b/reference/C/SYNTAX/conditional.html @@ -0,0 +1,120 @@ +<title>Conditional Expressions</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Conditional Expressions.</h1> +</center> +<hr> +<p> + + +We have a short-hand construct for some <b>if ... else ...</b> constructs.<p> +Consider the following two examples. +<p> +<center> +<table border=2 bgcolor=ivory> +<th>Example 1</th> +<th>Example 2</th> +<tr> +<td> +<pre> + + if ( x == 1 ) + y = 10; + else + y = 20; + +</pre> +</td> +<td> +<pre> + + y = (x == 1) ? 10 : 20; + +</pre> +</td> +</tr> +</table> +</center> +<p> +These examples both perform the same function. If x is 1 then y becomes 10 +else y becomes 20. The example on the right evaluates the first expression +'(x ==1 )' and if <b>true</b> evaluates the second '10'. If <b>false</b> the +third is evaluated. Here is another example. +<p> +<center> +<table border=2 bgcolor=ivory> +<th>Example 1</th> +<th>Example 2</th> +<tr> +<td> +<pre> + + if ( x == 1 ) + puts("take car"); + else + puts("take bike"); +</pre> +</td> +<td> +<pre> + + (x == 1) ? puts("take car") : puts("take bike"); + + or + + puts( (x == 1) ? "take car" : "take bike"); +</pre> +</td> +</tr> +</table> +</center> +<p> +It has been said that the compiler can create more efficent code from +a <b>conditional expression</b> possibly at the expence of readable code. +Unless you are writing time critical code (and lets face it, thats unlikely) +the more efficent code is not much of a reason to use this construct. +I feel that it has its uses, but should not be lost into some complex +statement, +but, since when did C programmers worry if anyone else could read their +code ;-) +<p> +<hr> +<h2>See also:</h2> +<ul> +<li><a href="if.html">if</a> keyword. +<li><a href="switch.html">switch</a> keyword. +<li><a href="idioms.html#printf">A use within printf.</a>. +</ul> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/const.html b/reference/C/SYNTAX/const.html new file mode 100644 index 0000000..3ca3683 --- /dev/null +++ b/reference/C/SYNTAX/const.html @@ -0,0 +1,212 @@ +<head> +<title>The const keyword.</title> + +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The const keyword.</h1> +</center> +<hr> + +The const keyword is used to create a read only variable. Once initialised, +the value of the variable cannot be changed but can be used just like +any other variable. + +<h2>const syntax</h2> +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + main() + { + const float pi = 3.14; + } +</pre> +</td></tr> +</table> +</center> +<p> +The const keyword is used as a qualifier to the following data types - +int float char double struct. +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + const int degrees = 360; + const float pi = 3.14; + const char quit = 'q'; +</pre> +</td></tr> +</table> +</center> +<p> +<h2>const and pointers.</h2> + +Consider the following example. +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + void Func(const char *Str); + + main() + { + char *Word; + + Word = (char *) malloc(20); + + strcpy(Word, "Sulphate"); + + Func(Word); + } + + void Func(const char *Str) + { + } +</pre> +</td></tr> +</table> +</center> +<p> +The <code>const char *Str</code> tells the compiler that the DATA the +pointer points too is <code>const</code>. This means, Str can be changed +within Func, but *Str cannot. As a copy of the pointer is passed to Func, +any changes made to Str are not seen by main.... + +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + -------- + | Str | Value can be changed + -----|-- + | + | + V + -------- + | *Str | Read Only - Cannot be changed. + -------- +</pre> +</td></tr> +</table> +</center> +<p> + +<h2>Geeky Stuff</h2> + +It is still possible to change the contents of a 'const' variable. +<a href=../EXAMPLES/const2.c>Consider this program</a> it creates +a const variable and then changes its value by accessing the data by +another name. +<p> +I am not sure if this applies to all compilers, but, +you can place the 'const' after the datatype, for example: +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + int const degrees = 360; + float const pi = 3.14; + char const quit = 'q'; +</pre> +</pre> +</td></tr> +</table> +</center> +<p> +are all valid in 'gcc'. +<p> +<h2>More Geeky Stuff</h2> + +What would you expect these to do? +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + main() + { + const char * const Variable1; + char const * const Variable2; + }; +</pre> +</td></tr> +</table> +</center> +<p> +These both make the pointer and the data read only. +Here are a few more examples. +<p> +<center> +<table bgcolor=ivory width="80%" border=1> +<tr><td> +<pre> + + const int Var; /* Var is constant */ + int const Var; /* Ditto */ + int * const Var; /* The pointer is constant, + * the data its self can change. */ + const int * Var; /* Var can not be changed. */ + +</pre> +</td></tr> +</table> +</center> +<p> + +<hr> +<h2>See Also.</h2> +<img src="../../GRAPHICS/whiteball.gif" alt="o"> +<a href="../SYNTAX/define_preprocessor.html">#define preprocessor</a> +<p> +<font color=brown> +<img src="../../GRAPHICS/whiteball.gif" alt="o"> +C++ version of +<a href="../../CPLUSPLUS/SYNTAX/const.html">const</a> +</font> + +<hr> +<h2>An Example.</h2> +<img src="../../GRAPHICS/computer.gif" alt="o"> +<a href=../EXAMPLES/const.c> const</a> example. + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/continue.html b/reference/C/SYNTAX/continue.html new file mode 100644 index 0000000..7c8d22a --- /dev/null +++ b/reference/C/SYNTAX/continue.html @@ -0,0 +1,46 @@ +<title>The continue statement</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The continue statement </h1> +</center> +<hr> +continue allows a new iteration of a loop without the current iteration +completing. For example you could filter records from a file with +the 'continue' statement. +<p> +<a href="../EXAMPLES/continue.c"><img src="../../GRAPHICS/computer.gif"></a> +continue example.<p> + +continue is related to the <a href="break.html">break</a> +statement.<p> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/define_preprocessor.html b/reference/C/SYNTAX/define_preprocessor.html new file mode 100644 index 0000000..4023d2b --- /dev/null +++ b/reference/C/SYNTAX/define_preprocessor.html @@ -0,0 +1,77 @@ +<title>define preprocessor</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>#define preprocessor</h1></center> +<hr> +<p> +The <b>#define</b> preprocessor allows us to define symbolic names and constants. +A quick example<p> +<pre> + #define PI 3.14159 +</pre> +This statement will translate every occurance of PI in the program to 3.14159. +Here is a more complete example:<p> +<pre> + + #define PI 3.14159 + main() + { + int r=10; + float cir; + cir = PI * (r*r); + } +</pre> +This feature is partically usefull for defining 'magic' numbers.<p> + +<hr> +<h2>See Also:</h2> +<ul> +<li>A related C keyword is <a href=enum.html>enum</a> which can be used to +build lists of aliases.<p> + +<li>Another related C keyword is <a href=const.html>const</a>. +<p> + +<li>An advanced use of #define is in the creation of <a href=macros.html> +macros</a>. +</ul> + +<hr> +<h2>Examples:</h2> +<a href="../EXAMPLES/define.c"><img src="../../GRAPHICS/computer.gif"></a> +example program.<p> + +<a href="../EXAMPLES/enum5.c"><img src="../../GRAPHICS/computer.gif"></a> +Conflict between enum and #define.<p> + +<p> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/do.html b/reference/C/SYNTAX/do.html new file mode 100644 index 0000000..da05f59 --- /dev/null +++ b/reference/C/SYNTAX/do.html @@ -0,0 +1,81 @@ +<title>The DO keyword.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The DO keyword.</h1></center> +<hr> +The <b>do</b> keyword performs a simular function to +<a href="while.html">while</a>. Basicaly, it repeats a block of statements. +Here is an example of the syntax: +<pre> + main() + { + int i=5; + + do + { + printf(" i is %d\n", i); + } + while(--i); + } + +</pre> + +The program result will look like this: +<pre> + i is 5 + i is 4 + i is 3 + i is 2 + i is 1 +</pre> +The main difference between <b>do</b> and <a href=while.html>while</a> is +the time that expression is evaluated. +<ul> +<li><b>do</b> performs the first test AFTER the first iteration. +<li><b>while</b> performs the first test BEFORE the first iteration. +</ul> +<hr> +<h2>Examples:</h2> + +<a href=../EXAMPLES/do.c><img src="../../GRAPHICS/computer.gif" align=left></a> +Basic <b>do</b>. +<br clear=left> + +<hr> +<h2>See also:</h2> +<ul> +<li><a href="while.html">while</a> keyword. +<li><a href="for.html">for</a> keyword. +<li><a href="break.html">break</a> keyword. +<li><a href="continue.html">continue</a> keyword. +</ul> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/enum.html b/reference/C/SYNTAX/enum.html new file mode 100644 index 0000000..8f6b393 --- /dev/null +++ b/reference/C/SYNTAX/enum.html @@ -0,0 +1,97 @@ +<title>The enum statement</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The enum statement</h1> +</center> +<hr> +<p> +ENUM is closely related to the <a href="define_preprocessor.html">#define</a> +preprocessor.<p> +It allows you to define a list of aliases which represent integer numbers. For +example if you find yourself coding something like: +<pre> + #define MON 1 + #define TUE 2 + #define WED 3 +</pre> +You could use <b>enum</b> as below. +<pre> + enum week { Mon=1, Tue, Wed, Thu, Fri Sat, Sun} days; + or + enum escapes { BELL = '\a', BACKSPACE = '\b', HTAB = '\t', + RETURN = '\r', NEWLINE = '\n', VTAB = '\v' }; + + or + enum boolean { FALSE = 0, TRUE }; + +</pre> + +An advantage of <b>enum</b> over <b>#define</b> is that it has +<a href="../glossary.html#scope">scope</a> +This means that the variable (just like any other) is only visable +within the block it was declared within. +<p> +<hr> +<h2>Notes:</h2> +<ul> +<li>If a variable is +<a href="../glossary.html#definition">defined</a> +with <b>enum</b> it is considered by +the compiler to be an integer, and can have ANY integer value assigned +to it, it is not restericted to the values in the enum statement. +</ul> + + +<hr> +<h2>See Also:</h2> + +<a href=../../CPLUSPLUS/SYNTAX/enum.html> C++ Enhancements to enum.</a><p> +<a href=define_preprocessor.html>#define</a> preprocessor.<p> + +<hr> +<h2>Examples:</h2> + +<a href="../EXAMPLES/enum1.c"><img src="../../GRAPHICS/computer.gif"></a> +enum example 1.<p> +<a href="../EXAMPLES/enum2.c"><img src="../../GRAPHICS/computer.gif"></a> +enum example 2.<p> + +<a href="../EXAMPLES/enum3.c"><img src="../../GRAPHICS/computer.gif"></a> +enum coding error.<p> + +<a href="../EXAMPLES/enum4.c"><img src="../../GRAPHICS/computer.gif"></a> +Another enum coding error.<p> + +<a href="../EXAMPLES/enum5.c"><img src="../../GRAPHICS/computer.gif"></a> +enum and #define coding error.<p> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/for.html b/reference/C/SYNTAX/for.html new file mode 100644 index 0000000..e90ac20 --- /dev/null +++ b/reference/C/SYNTAX/for.html @@ -0,0 +1,175 @@ +<title>The FOR keyword.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The FOR keyword.</h1></center> +<hr> +The <b>for</b> <a href="../glossary.html#keyword">keyword</a> is used to +repeat a block of code many times. +<p> +<ul> +<li><a href=#basic>Basic principles.</a> +<li><a href=#repeat>Repeating several lines of code</a> +<li><a href=#detail>More detail</a> +</ul> +<a name=basic> +<hr> +<h2>Basic principles</h2> +Say you wanted to print all the numbers between 1 and 10, you could write: +<pre> + main() + { + int count=1; + + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + printf("%d\n", count++); + } +</pre> + +As you can see this program would NOT be very practical if we wanted +1000 numbers. The problem can be solved with the <b>for</b> statement +as below. +<pre> + main() + { + int count; + + for ( count=1 ; count <= 10 ; count++) printf("%d\n", count); + } +</pre> + +The <b>for</b> statement can be broken down into 4 sections: +<p> +<dl> +<dt><samp>count=1</samp> +<dd>is the initalisation.<p> + +<dt><samp>count <= 10 </samp> +<dd>An expression. The for statement continues to loop while this +statement remains <a href="../CONCEPT/true_false.html">true</a><p> + +<dt><samp>count++ </samp> +<dd><a href="../CONCEPT/inc_dec.html">increament</a> or +<a href="../CONCEPT/inc_dec.html">decreament</a>.<p> + +<dt><samp>printf("%d\n", count) </samp> +<dd>the statement to execute.<p> +</dl> + +<a name=repeat> +<hr> +<h2>Repeating several lines of code</h2> + +The previous example showed how to repeat ONE statement. This example +shows how many lines can be repeated. + +<pre> + main() + { + int count, sqr; + + for ( count=1 ; count <= 10 ; count++) + { + sqr=count * count; + printf( " The square of"); + printf( " %2d", count); + printf( " is %3d\n", sqr); + } + } +</pre> + +The <b>{</b> and <b>}</b> following the <b>for</b> statement define +a <a href=statements.html#block>block</a> of statements. + +<a name=detail> +<hr> +<h2>More detail</h2> + +The <b>for</b> statement performs the following functions while looping. + +<pre> + for (expression_1 ; expression_2 ; expression_3) statement ; +</pre> +<ol> +<li>Executes <samp>expression_1</samp>.<p> +<li>Executes <samp>statement</samp>. +<li>Executes <samp>expression_3</samp>. +<li>Evaluates <samp>expression_2</samp>. +<p> +<ul> +<li>If TRUE, Jumps to item 2. +<li>If FALSE, Stops looping. +</ul> +</ol> + +Any of the three expressions can be missing, if the first or third is missing, +it is ignored. If the second is missing, is is assumed to be TRUE.<p> + +The following example is an infinite loop: + +<pre> + main() + { + for( ; ; ) puts(" Linux rules!"); + } +</pre> + + + +<hr> +<h2>Examples:</h2> + +<a href=../EXAMPLES/for1.c><img src="../../GRAPHICS/computer.gif" align=left></a> +Basic <b>for</b> example. +<br clear=left> + +<a href=../EXAMPLES/for2.c><img src="../../GRAPHICS/computer.gif" align=left></a> +Advanced <b>for</b> example. +<br clear=left> + +<hr> +<h2>See also:</h2> +<ul> +<li><a href="while.html">while</a> keyword. +<li><a href="do.html">do</a> keyword. +<li><a href="continue.html">continue</a> keyword. +<li><a href="break.html">break</a> keyword. +<li><a href="got_ya.html#num1">for got_ya</a>. +</ul> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/fork1.c b/reference/C/SYNTAX/fork1.c new file mode 100644 index 0000000..d99288f --- /dev/null +++ b/reference/C/SYNTAX/fork1.c @@ -0,0 +1,24 @@ + +#include <unistd.h> + +main() +{ + + pid_t ForkPID; + + printf("Program start. \n"); + + ForkPID = fork(); /* Create a child and copy the parents + * parent data space, heap and stack. + */ + + /* ForkPID == -1 Fork failure. + * == 0 This is the child process. + * > 0 This is the parent process. The number given is the + * PID of the child. + */ + + printf("forkPID is %d \n", ForkPID); /* Child execution starts here. */ + printf("Program end. \n"); +} + diff --git a/reference/C/SYNTAX/functions.html b/reference/C/SYNTAX/functions.html new file mode 100644 index 0000000..1f14822 --- /dev/null +++ b/reference/C/SYNTAX/functions.html @@ -0,0 +1,138 @@ +<title>Functions and passing arguments.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<center> +<hr> +<h1>Functions and passing arguments.</h1> +<hr> +</center> +A function is a block of code that can be executed many times by other +functions or its self. +<ul> +<li><a href=#2.1>Function basics.</a> +<li><a href=#2.2>Declaration.</a> +<li><a href=#2.3>Definition.</a> +<li><a href=#2.4>Passing values.</a> +<li><a href=#2.5>Passing pointers.</a> +<li><a href=#2.6>Passing Arrays.</a> +<li><a href=#2.7>Variable number of parms</a> +<li><a href=#2.8>Function recurssion.</a> +<li><a href=#2.9>Returning values.</a> +<li><a href=#2.10>Returning pointers.</a> +<font color="brown"> +<li> C++ <a href="../../CPLUSPLUS/CONCEPT/reference_variable.html">Reference variables</a> +<li> C++ <a href="../../CPLUSPLUS/CONCEPT/fundefault.html">Default parameters.</a> +<li> C++ <a href="../../CPLUSPLUS/CONCEPT/funcoverload.html">Function Overloading.</a> +</font> +</ul> + +<hr> +<a name=2.1><h2>Function Basics.</h2> +You should already understand the concept of functions! If you don't, you +are a sad sad man....<p> +Might expand on this one day.<p> +P.S. main() is a function. + +<a name=2.2><h2>Declaration.</h2> +Just like variables, all functions have to be +<a href="../glossary.html#declaration">declared</a> before use. Here is an +example. +<pre> + int add( int, int); +</pre> +This statement declares a function called <b>add</b>, it has two integer +arguments and returns an integer. + +<a name=2.3><h2>Definition.</h2> +The <a href="../glossary.html#definition">definition</a> is the meat of the +function. Heres an <a href="../EXAMPLES/function.c">example.</a> + +<a name=2.4><h2>Passing values.</h2> +Passing values is known as <b>call by value.</b> You actually pass a copy +of the variable to the function. If the function modifies the copy, the original +remains unaltered. The previous example demonstarted <b>call by value</b> +<a name=2.5><h2>Passing pointers.</h2> +This is known as <b>call by reference</b> and is an area worth spending some +time on. We do not pass the data to the function, instead we pass a pointer +to the data. This means that if the function alters the data, the original +is altered.<p> +<dd><img src="../../GRAPHICS/whiteball.gif"> +<a href="../EXAMPLES/pointer_func.c"> Example of passing a pointer to a scalar.</a> +<p> + +<font color=brown> +C++ has a nice feature called +<a href="../../CPLUSPLUS/CONCEPT/reference_variable.html">reference variables</a> +which is a tider +approch to modifing the contents of a passed variable. +</font> + +<a name=2.6><h2>Passing Arrays.</h2> +<dd><img src="../../GRAPHICS/whiteball.gif"> +<a href="../EXAMPLES/pointer1_func.c"> Example of passing a pointer to an integer array.</a> +<dd><img src="../../GRAPHICS/whiteball.gif"> +<a href="../EXAMPLES/pointer2_func.c"> Example of passing a pointer to a two +dimensional integer array.</a> +<dd><img src="../../GRAPHICS/whiteball.gif"> +<a href="../EXAMPLES/pointer3_func.c"> Example of passing a pointer to a +character array.</a> +<dd><img src="../../GRAPHICS/whiteball.gif"> +<a href="../EXAMPLES/pointer4_func.c"> Example of passing a two dimensional +character array.</a> +<h2><a name=2.7>Variable number of parms (...)</a></h2> + +<dd><img src="../../GRAPHICS/whiteball.gif"> +<a href="../EXAMPLES/var_func.c"> Example of passing an unknown number +of variables to a function</a> + +<dd><img src="../../GRAPHICS/man.gif"> +<a href="../MAN/va_start.htm"> Man page for va_start, va_end etc</a> + +<a name=2.8><h2>Function recurssion.</h2> +<a name=2.9><h2>Returning values.</h2> + +Normally you would return an 'int', 'char', 'float', or 'double' using this +technic. The obvious time to return a value would be to return a completion +code. +<p> +Here is an <a href="../EXAMPLES/function.c">example</a> +<p> +The contents of 'c' are copied into 'i'. + +<a name=2.10><h2>Returning pointers.</h2> + +Returning values is OK for the data types above but not very practical for +'char *' or structures. For these data types passing pointers can be more +appropriate. When using these pointers it is important to understand the +'<a href="../CONCEPT/storage_class.html#static2">static</a>' storage class +otherwise you are going to get some unpredictable +results. + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/glo_int_vars.html b/reference/C/SYNTAX/glo_int_vars.html new file mode 100644 index 0000000..51991c4 --- /dev/null +++ b/reference/C/SYNTAX/glo_int_vars.html @@ -0,0 +1,214 @@ +<title>Global and Local variables declaration.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Global and Local variables.</h1> +</center> +<hr> +<p> + +<h2>Local variables</h2> +Local variables must always be +<a href="../glossary.html#definition">defined</a> +at the top of a block. +<p> +<font color="brown"> +C++ has changed the rules regarding where you can define a +local variable. +<a href=../../CPLUSPLUS/CONCEPT/local_var.html>Click here</a> +for the low down. +</font> +<p> +When a local variable is +<a href="../glossary.html#definition">defined</a> +- it is not initalised by the system, you +must initalise it yourself.<p> +A local variable is +<a href="../glossary.html#definition">defined</a> + inside a <b>block</b> and is only visable +from within the block. +<p> +<center> +<table border=1 width="80%" bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int i=4; + i++; + } + +</pre> +</td> +</tr> +</table> +</center> +<p> +When execution of the block starts the variable is +available, and when the block ends the variable 'dies'.<p> +A local variable is visible within nested blocks unless a variable with +the same name is +<a href="../glossary.html#definition">defined</a> + within the nested block. +<p> +<center> +<table border=1 bgcolor=ivory width="80%"> +<tr> +<td> +<pre> + + main() + { + int i=4; + int j=10; + + i++; + + if (j > 0) + { + printf("i is %d\n",i); /* i defined in 'main' can be seen */ + } + + if (j > 0) + { + int i=100; /* 'i' is defined and so local to + * this block */ + printf("i is %d\n",i); + } /* 'i' (value 100) dies here */ + + printf("i is %d\n",i); /* 'i' (value 5) is now visable. */ + } + +</pre> +</td> +</tr> +</table> +</center> +<p> +<a name="global"> +<hr width="50%" align=center> +<h2>Global variables</h2> + +<font color="brown"> +C++ has enhanced the use of +<a href=../../CPLUSPLUS/CONCEPT/scope.html> global variables.</a> +</font> +<p> +Global variables ARE initalised by the system when you +<a href="../glossary.html#definition">define</a> + them! +<p> +<center> +<table border=2 width="50%" bgcolor=ivory> +<tr align=center><td> Data Type </td><td> Initialser </td> </tr> +<tr align=center><td> int </td><td> 0 </td> </tr> +<tr align=center><td> char </td><td> '\0' </td> </tr> +<tr align=center><td> float </td><td> 0 </td> </tr> +<tr align=center><td> pointer </td><td> NULL </td> </tr> + +</table> +</center> +<p> +In the next example <b>i</b> is a global variable, it can be seen and modified by +<b> main </b>and any other functions that may reference it. +<p> +<center> +<table border=1 width="80%" bgcolor=ivory> +<tr> +<td> +<pre> + + int i=4; + + main() + { + i++; + } + +</pre> +</td> +</tr> +</table> +</center> +<p> + +Now, this example has <b>global</b> and <b>Internal</b> variables. +<p> +<center> +<table border=1 width="80%" bgcolor=ivory> +<tr> +<td> +<pre> + + int i=4; /* Global definition */ + + main() + { + i++; /* global variable */ + func + } + + func() + { + int i=10; /* Internal declaration */ + i++; /* Internal variable */ + } + +</pre> +</td> +</tr> +</table> +</center> +<p> + +<b>i</b> in <b>main</b> is global and will be incremented to 5. <b>i</b> in +<b>func</b> is internal and will be incremented to 11. When control returns +to <b>main</b> the internal variable will die and and any reference to +<b>i</b> will +be to the global.<p> + + +static variables can be 'seen' within all functions in this source file. At +link time, the static variables defined here will not be seen by the object +modules that are brought in.<p> +<hr> +<h2>Example:</h2> +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/global.c">An Example program</a>. +<hr> +<h2>See Also:</h2> +See <a href="../CONCEPT/storage_class.html">Storage classes</a> to see the more powerfull +features of variable declarations. + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> + diff --git a/reference/C/SYNTAX/got_ya.html b/reference/C/SYNTAX/got_ya.html new file mode 100644 index 0000000..4781430 --- /dev/null +++ b/reference/C/SYNTAX/got_ya.html @@ -0,0 +1,80 @@ +<title>Got Ya</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Got Ya</h1> +</center> +<hr> +<ul> +<li><a href="#num1">== and =</a> +<li><a href="#num1">if</a> +</ul> + +<a name=num1> +<hr> +An error which almost every C programmer has made is shown below: +<pre> + main() + { + int left=10; + + if ( left = 5 ) + { + puts(" Values are equal..."); + } + } +</pre> +The program assigns 5 to the variable <b>left</b> and returns 5. +This is interpreted as <a href="../CONCEPT/true_false.html">TRUE</a> and causes the +<a href="../FUNCTIONS/puts.html">puts</a> statement to be executed everytime. +<p> +Here is the corrected program. +<pre> + main() + { + int left=10; + + if ( left == 5 ) /* Double equals required. */ + { + puts(" Values are equal..."); + } + } +</pre> + +<hr> + +<hr> +<h2>See Also:</h2> + +<img src="../../GRAPHICS/whiteball.gif"> +<a href="idioms.html">Coding idioms</a>.<p> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/goto.html b/reference/C/SYNTAX/goto.html new file mode 100644 index 0000000..156534a --- /dev/null +++ b/reference/C/SYNTAX/goto.html @@ -0,0 +1,59 @@ +<title>The GOTO keyword.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The GOTO keyword.</h1> +</center> +<hr> +Well, I have resisted adding <b>goto</b> for a whole year. But tonight +I have had a couple of beers and +I am ready to go for it. It must be said +that most programmers will claim that +<b>goto</b> is never required and I dont have reason to disagree, but +you may like to differ. + +<h2>goto syntax</h2> + +<pre> + goto lab1; + + lab1: +</pre> +goto allows the program to 'jump' to a named label, in this case <b>lab1</b>, +the target label MUST be terminated with a : (colon). + + +<hr> +<h2>An Example.</h2> +<a href="../EXAMPLES/goto.c"><img src="../../GRAPHICS/computer.gif"></a> +goto example. + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/idioms.html b/reference/C/SYNTAX/idioms.html new file mode 100644 index 0000000..62247d3 --- /dev/null +++ b/reference/C/SYNTAX/idioms.html @@ -0,0 +1,136 @@ +<title>Idioms</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Idioms</h1> +</center> +<hr> +<p> + +Here are some C idioms that may be usefull. + +<p><hr align=center width="50%"><p> +Place <code>\0</code> at the location pointed to by <code>ptr</code> +then increment <code>ptr</code> +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + *ptr++ = '\0'; +</pre> +</td></tr> +</table> +</center> + +<p><hr align=center width="50%"><p> +Increment <code>ptr</code> then +place <code>\0</code> at the location pointed to by <code>ptr</code> +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + *++ptr = '\0'; +</pre> +</td></tr> +</table> +</center> + +<p><hr align=center width="50%"><p> +This program will print its self! I guess its not of any real +use, but I think its clever. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main(a) {a="main(a) {a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);} +</pre> +</td></tr> +</table> +</center> + +<p><hr align=center width="50%"><p> +This is something I saw out on the web. It swaps the value of two +variables without +using a third variable as a temporary store. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + one ^= two; + two ^= one; + one ^= two; +</pre> +</td></tr> +</table> +</center> + +<a name=printf> +<p><hr align=center width="50%"><p> + +Have you ever had a SEGV from <a href="../FUNCTIONS/printf.html">printf</a> +because you passed a NULL pointer to a %s flag???. This idiom will put +a stop to all that nonsence. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + printf("%s\n", Str ? Str : "Null"); +</pre> +</td></tr> +</table> +</center> + + + +<p><hr align=center width="50%"><p> +<p> +<img src="../../GRAPHICS/computer.gif" alt="o"> +<a href=../EXAMPLES/swap.c>Program swapping the contents of two variables</a>. +<p> + +<hr> +<h2>See Also:</h2> + +<img src="../../GRAPHICS/whiteball.gif" alt="o"> +<a href="got_ya.html">Common Coding Errors</a>.<p> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/if.html b/reference/C/SYNTAX/if.html new file mode 100644 index 0000000..8df9bb6 --- /dev/null +++ b/reference/C/SYNTAX/if.html @@ -0,0 +1,133 @@ +<title>if-else keywords.</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The 'if' and 'else' keywords</h1> +</center> +<hr> +<p> + +The if-else statement is a two-way decision statement. It is written as + +<pre> + if ( expression ) statement1; + [else statement2;] +</pre> + +The else portion is optional. If the expression evaluates to +<a href="../CONCEPT/true_false.html">true</a> +(anything other than 0) then statement1 is executed. If there is an <b>else</b> +statement and the expression evaluates to +<a href="../CONCEPT/true_false.html">false</a> +statement2 is executed. + +For example + +<pre> +(1) + int NumberOfUsers; + . + . + if( NumberOfUsers == 25 ) + { /* No else part */ + printf( "There are already enough users. Try later.\n" ); + return ERROR; + } + . + . + + +(2) if( a >= b ) larger = a; /* else part is present */ + else larger = b; +</pre> + +Consider this code fragment: +<pre> + if( p == 1 ) + if( q == 2 ) r = p * 2 + q; + else r = q * 2 + p; +</pre> +Because the <b>else</b> part is optional, there is an ambiguity when an <b>else</b> is +omitted from a nested if sequence. In 'C', this is resolved by associating +the <b>else</b> with the closest previous if that does not have an <b>else</b>. +Therefore, in the above example, the <b>else</b> part belongs to the if(q==2) +statement. + +The code can be made more readable by explicitly putting parentheses in +the expression, like this + +<pre> + if( p == 1 ) + { + if( q == 2 ) r = p * 2 + q; + } + else r = q * 2 + p; + + OR + + if( p == 1 ) + { + if( q == 2 ) r = p * 2 + q; + else r = q * 2 + p; + } +</pre> + +Because the statement in the <b>else</b> part can also be an if statement, a +construct such as shown below is possible in 'C' to create a multiple +choice construct. + +<pre> + if( expression1 ) + statement1; + else if( expression2 ) + statement2; + else if( expression3 ) + statement3; + . + . + else + statementN; +</pre> + +<hr> +<h2>Example:</h2> +<img src="../../GRAPHICS/computer.gif" align=center> +<a href="../EXAMPLES/if.c"> Basic <b>if</b> example.</a> +<br clear=left> +<hr> +<h2>See also:</h2> +<ul> +<li><a href="switch.html">switch</a> keyword. +</ul> +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> + + </body> +</html> diff --git a/reference/C/SYNTAX/include_preprocessor.html b/reference/C/SYNTAX/include_preprocessor.html new file mode 100644 index 0000000..cd88707 --- /dev/null +++ b/reference/C/SYNTAX/include_preprocessor.html @@ -0,0 +1,61 @@ +<title>include preprocessor</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>include preprocessor.</h1> +</center> +<hr> +The include preprocessor will add source code to your existing source. This +is used to include <i>header</i> files that contain function declarations. +For example:<p> +<pre> + #include <stdio.h> + main() + printf("hi peeps"); + } +</pre> +The <i>printf</i> function declaration is held in stdio.h<p> +There are two ways of defining the include files location. +<ul> +<li><>says to the preprocessor that the file is in the system libraries. +<pre> + #include <stdio.h> +</pre> + +<li>""means that this is a user defined file. Absolute or relative +paths may be defined. +<pre> + #include "myheaders.h" + #include "/usr/home/leslim/myheaders.h" +</pre> +</ul> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/keywords.html b/reference/C/SYNTAX/keywords.html new file mode 100644 index 0000000..586ddcb --- /dev/null +++ b/reference/C/SYNTAX/keywords.html @@ -0,0 +1,115 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.5 [en] (X11; I; Linux 2.0.36 i586) [Netscape]"> + <title>C keywords.</title> +</head> +<body bgcolor="#FFFFCC"> + +<hr> +<center> +<h1> +C keywords.</h1></center> + +<hr>The following list shows all the ANSII defined C keywords. I have included +<a href="sizeof.html">sizeof</a> because it looks like a keyword and it +keeps the table below tidy.... +<center><table BORDER=2 CELLPADDING=5 BGCOLOR="#FFFFF0" > +<tr ALIGN=CENTER> +<td><a href="../CONCEPT/storage_class.html#auto">auto</a></td> + +<td><a href="break.html">break</a></td> + +<td><a href="switch.html">case</a></td> + +<td><a href="../CONCEPT/data_types.html#char">char</a></td> + +<td><a href="../CONCEPT/data_types.html#qualifier">const</a></td> + +<td><a href="continue.html">continue</a></td> + +<td><a href="switch.html">default</a></td> + +<td><a href="do.html">do</a></td> +</tr> + +<tr ALIGN=CENTER> +<td><a href="../CONCEPT/data_types.html#double">double</a></td> + +<td><a href="if.html">else</a></td> + +<td><a href="enum.html">enum</a></td> + +<td><a href="../CONCEPT/storage_class.html#extern">extern</a></td> + +<td><a href="../CONCEPT/data_types.html#float">float</a></td> + +<td><a href="for.html">for</a></td> + +<td><a NAME="goto"></a><a href="goto.html">goto</a></td> + +<td><a href="if.html">if</a></td> +</tr> + +<tr ALIGN=CENTER> +<td><a href="../CONCEPT/data_types.html#int">int</a></td> + +<td><a href="../CONCEPT/data_types.html#modifier">long</a></td> + +<td><a href="../CONCEPT/storage_class.html#register">register</a></td> + +<td><a href="return.html">return</a></td> + +<td><a href="../CONCEPT/data_types.html#modifier">short</a></td> + +<td><a href="../CONCEPT/data_types.html#modifier">signed</a></td> + +<td><a href="sizeof.html">sizeof</a></td> + +<td><a href="../CONCEPT/storage_class.html#static">static</a></td> +</tr> + +<tr ALIGN=CENTER> +<td><a href="struct.html">struct</a></td> + +<td><a href="switch.html">switch</a></td> + +<td><a href="typedef.html">typedef</a></td> + +<td><a href="union.html">union</a></td> + +<td><a href="../CONCEPT/data_types.html#modifier">unsigned</a></td> + +<td><a href="void.html">void</a></td> + +<td><a href="volatile.html">volatile</a></td> + +<td><a href="while.html">while</a></td> +</tr> +</table></center> + +<p> +<hr><font color="#A52A2A">C++ extends the language to include <a href="../../CPLUSPLUS/SYNTAX/keywords.html">these +keywords</a></font> +<br> +<hr> +<center><table BORDER=2 WIDTH="80%" BGCOLOR="#FFFFF0" > +<tr ALIGN=CENTER> +<td WIDTH="25%"><a href="../cref.html">Top</a></td> + +<td WIDTH="25%"><a href="../master_index.html">Master Index</a></td> + +<td WIDTH="25%"><a href="keywords.html">Keywords</a></td> + +<td WIDTH="25%"><a href="../FUNCTIONS/funcref.htm">Functions</a></td> +</tr> +</table></center> + +<p> +<hr> +<address> +Martin Leslie</address> + +</body> +</html> diff --git a/reference/C/SYNTAX/logical.html b/reference/C/SYNTAX/logical.html new file mode 100644 index 0000000..54cb246 --- /dev/null +++ b/reference/C/SYNTAX/logical.html @@ -0,0 +1,102 @@ +<title>Logical AND OR and NOT</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Logical AND OR and NOT</h1> +</center> +<hr> + +<ul> +<li><a href=#AND>Logical AND is &&</a> +<li><a href=#OR>Logical OR is ||</a> +<li><a href=#NOT>Logical NOT is !</a> +</ul> +<hr> +<a name=AND> +<h2>Logical AND</h2> +In simple terms, && is true (1) if both sides of the expression returns NOT 0. +<p> +For Example: +<pre> + /* These all return TRUE (1) */ + + if (4 && 5) return(); + + i=3; + j=2; + return( i && j); +</pre> +The expression is evaluated 'Left to Right' If any part of the expression +returns ZERO - The evaluation ends. +<p> +THIS CAN CAUSE SERIOUS PROBLEMS. +<p> +For example: +<pre> + k=0; + i=3; + j=2; + if ( i-i && j++) k=1 +</pre> +The left side <i>(i-i)</i> resolves to 0, so <i>j</i> is not incremented +and <i>k</i> is not changed. +<hr> +<a name=OR> +<h2>Logical OR</h2> +OR also evaluates 'Left to Right' and will stop when an expression +returns true. <p> +SO WATCH YOUR BACK.... +<p> +<pre> + k=0; + i=3; + j=2; + if ( i+i && j++) k=1 +</pre> +What are <i>j</i> and <i>k</i> going to be when this code is executed????? + +<hr> +<a name=NOT> +<h2>Logical NOT</h2> + +NOT reverses the logical state of its +<a href=../glossary.html#operand>operand</a>. If the operand is 0, 1 is +returned, else 0 is returned. + +<pre> + !4 /* Returns 0 */ + !-4 /* Returns 0 */ + !1 /* Returns 0 */ + !0 /* Returns 1 */ +</pre> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/macros.html b/reference/C/SYNTAX/macros.html new file mode 100644 index 0000000..b7726cf --- /dev/null +++ b/reference/C/SYNTAX/macros.html @@ -0,0 +1,96 @@ +<title>Macros</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Macros</h1> +</center> +<hr> +<p> +Macros are built on the <a href="define_preprocessor.html">#define</a> +preprocessor.<p> +Normally a #define would look like: +<pre> + #define PI 3.142 +</pre> +But, a macro would look like this. +<pre> + #define SQUARE(x) x*x +</pre> +The main difference is that the first example is a constant and the second +is an expression. +If the <b>macro</b> above was used in some code it may look like this: +<pre> + #define SQUARE(x) x*x + + main() + { + int value=3; + printf("%d \n", SQUARE(value)); + } +</pre> +After preprocessing the code would become: +<pre> + main() + { + int value=3; + printf("%d \n", value*value); + } +</pre> +<hr> +<h2>Examples:</h2> + +<a href="../EXAMPLES/macro.c"><img src="../../GRAPHICS/computer.gif"></a> +macro example.<p> +<hr> +<h2>Notes:</h2> +<ul> +<li>The value passed to SQUARE could have been an +<a href="../CONCEPT/data_types.html#int">int</a> +<a href="../CONCEPT/data_types.html#float">float</a> +or +<a href="../CONCEPT/data_types.html#double">double</a> +<li>Long macros can span multiple lines by using a +<a href="../FUNCTIONS/escape.html">\</a> followed by a newline +(return). +<li>If you are using gcc to compile your code, you can use the -E option to +see the preprocessor output +</ul> +<hr> +<h2>See Also:</h2> +<ul> +<li><A href="define_preprocessor.html">#define</a> preprocessor. +<font color=brown> +<li><A href="../../CPLUSPLUS/SYNTAX/inline.html">inline</a> A C++ keyword that provides a better aproch to macros. +</font> +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/namespace.html b/reference/C/SYNTAX/namespace.html new file mode 100644 index 0000000..3fdce4f --- /dev/null +++ b/reference/C/SYNTAX/namespace.html @@ -0,0 +1,46 @@ +<title>XXX</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>XXXX</h1> +</center> +<hr> +<b>XXXX</b> +<p> +<hr> +</pre> +<hr> +<h2>Examples:</h2> + +<img src="../../GRAPHICS/computer.gif"><a href="../EXAMPLES/malloc.c"> example</a> +program. + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/null.html b/reference/C/SYNTAX/null.html new file mode 100644 index 0000000..143b52a --- /dev/null +++ b/reference/C/SYNTAX/null.html @@ -0,0 +1,81 @@ +<title>Null</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>NULL</h1></center> +<hr> +<p> +NULL is used in several ways. +<ul> +<li>As a pointer to address zero. NULL is defined in several ANSI headers +as the +<a href="define_preprocessor.html">symbolic constant</a> +<a href="../CONCEPT/pointers.html#void">(void *)0</a>. Zero is often returned from +functions that normaly return a pointer to signal an error. It is therefore +conveniant to compare a function return code with NULL to catch errors. +<pre> + if ((fp=<a href="../FUNCTIONS/fopen.html">fopen</a>("/etc/hosts","r") == NULL) + { + exit(0); + } +</pre> +<p> +<li>To mark the end of a character string. A null character is used to +terminate the string. For example if you coded: +<pre> + char * text="abc"; +</pre> +You will actually reserve <b>FOUR</b> bytes containing in ASCII hex. +<pre> + 61 62 63 00 + a b c \0 +</pre> +The null at the end can be coded by using the +<a href="../FUNCTIONS/escape.html">escape sequence</a> '\0'. +</ul> +<p> +\0 is actually an octal <a href="../FUNCTIONS/escape.html">escape sequence</a>, +strictly speeking it should +be written as \000 +<p> +<hr> +<h2>ANSI headers</h2> +The following headers define NULL. +<ul> +<li><a href="../FUNCTIONS/funcref.htm#headers">locale.h</a> +<li><a href="../FUNCTIONS/funcref.htm#headers">stddef.h</a> +<li><a href="../FUNCTIONS/funcref.htm#headers">stdio.h</a> +<li><a href="../FUNCTIONS/funcref.htm#headers">stdlib.h</a> +<li><a href="../FUNCTIONS/funcref.htm#headers">string.h</a> +<li><a href="../FUNCTIONS/funcref.htm#headers">string.h</a> +<li><a href="../FUNCTIONS/funcref.htm#headers">time.h</a> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/preprocessors.html b/reference/C/SYNTAX/preprocessors.html new file mode 100644 index 0000000..5885253 --- /dev/null +++ b/reference/C/SYNTAX/preprocessors.html @@ -0,0 +1,83 @@ +<title>C compiler preprocessors</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>C compiler preprocessors</h1> +</center> +<hr> + +Preprocessor commands are executed before the compiler compiles the +source code. These commands will change the original code usually to +suit the operating environment and/or to add code that will be required by +calls to library functions. Preprocessors are recognised by the leading +# in their names. +<p> +<table border=2 bgcolor=ivory> +<Caption>Preprocessors</caption> +<tr> +<td><a href="include_preprocessor.html">#include</a> <td>Insert a source file. +<tr> +<td><a href="define_preprocessor.html">#define</a> <td>Define a preprocessor +constant. +<tr> +<td><a href="../EXAMPLES/if_else_endif.c">#if</a> <td>Branch based on an expression. +<tr> +<td>#ifdef <td>Branch if preprocessor constant has been defined? +<tr> +<td><a href="../EXAMPLES/ifndef.c">#ifndef</a> <td> Branch is a preprocessor +constant has NOT been defined. +<tr> +<td>#line <td> Specify the number of the next source line. +<tr> +<td>#undef <td> Remove a preprocessor constant. +<tr> +<td>#pragma<td> Perform an implementation dependent action??? +<tr> +<td><a href="../EXAMPLES/if_else_endif.c">#else</a> <td> Executed if #if +#ifdef or #ifndef fails. +<tr> +<td>#error <td> Write an error message. +<tr> +<td>#elif <td> Executed when an #if fails. +<tr> +<td><a href="../EXAMPLES/if_else_endif.c">#endif</a> <td>Close #if #ifdef or +#ifndef +</table> +<hr> +<H2>Notes:</H2> +<ul> +<li>Preprocessors should start in column 1. +<li>The -E option tells gcc to stop after the preprocessor stage and send the +O/P to STDOUT (usually the screen). +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/return.html b/reference/C/SYNTAX/return.html new file mode 100644 index 0000000..68a9c2c --- /dev/null +++ b/reference/C/SYNTAX/return.html @@ -0,0 +1,134 @@ +<title>The return statement</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The return statement </h1> +</center> +<hr> +<p> +<b>return</b> will return a value from a function to its caller. +The value returned is +the result of an <a href="../CONCEPT/expressions.html">expression</a>. +<p> +<hr> +As an Example this will print <b>7</b> + +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + int func(void); + + main() + { + printf("%d \n", func()); + } + + int func(void) + { + return 7; + } +</pre> +</td> +</tr> +</table> +<p> + +What ever follows the <b>return</b> statement will be evaluated as +an expression. So, to be consistant you could place brackets around +the return value. + +<p> +<table border=2 width="50%" bgcolor=ivory> +<tr> +<td> +<pre> + + return(7); +</pre> +</td> +</tr> +</table> +<p> +Or you could evaluate a formula on the statement: + +<p> +<table border=2 width="50%" bgcolor=ivory> +<tr> +<td> +<pre> + + return (Count-1); +</pre> +</td> +</tr> +</table> +<p> +Finally, if the function returns a <a href=void.html>void</a> +the <b>return</b> statement is not required, but maybe needed to +leave a function before the end of the function block. Here +is an example. + +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + void CheckDate(int) + + main() + { + CheckDate(40) + } + + void CheckDate(int Month) + { + if (Month > 31) + { + return; + } + + puts("Month is valid"); + } +</pre> +</td> +</tr> +</table> +<p> +<hr> +<h2>See also:</h2> +The <a href=../FUNCTIONS/exit.html>exit </a>function. + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/sizeof.html b/reference/C/SYNTAX/sizeof.html new file mode 100644 index 0000000..34dc287 --- /dev/null +++ b/reference/C/SYNTAX/sizeof.html @@ -0,0 +1,130 @@ +<title>The sizeof operator</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The sizeof operator</h1> +</center> +<hr> +<p> +<b>sizeof</b> will return the number of bytes reserved for a variable or +<a href="../CONCEPT/data_types.html">data type</a>. +<p> +The following code shows <b>sizeof</b> returning the length of a data type. +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + /* How big is an int? expect an answer of 4. */ + + main() + { + printf("%d \n", sizeof(int)); + } +</pre> +</td> +</tr> +</table> +<p> + +<b>sizeof</b> will also return the number of bytes reserved for a +<a href="struct.html">structure</a>. +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + /* Will print 8 on most machines. */ + + main() + { + struct + { + int a; + int b; + } TwoInts; + + printf("%d \n", sizeof(TwoInts)); + } + +</pre> +</td> +</tr> +</table> +<p> +Finally, <b>sizeof</b> will return the length of a variable. + +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + char String[20]; + + printf ("%d \n", sizeof String); + printf ("%d \n", sizeof (String)); + } + +</pre> +</td> +</tr> +</table> +<p> +In the example above I have printed the size of 'String' twice. This is to +show that when dealing with variables, the brackets are optional. + +I recommend that you always place the brackets around the sizeof argument. +<p> +<hr> +<h2>Examples:</h2> +<a href="../EXAMPLES/sizeof.c">Example 1</a> Data types. +<p> +<a href="../EXAMPLES/sizeof1.c">Example 2</a> Data objects. + +<p> +<hr> +<h2>See also:</h2> +<img src="../../GRAPHICS/whiteball.gif"> +The <a href="../FUNCTIONS/strlen.html">strlen </a>function. +<p> +<img src="../../GRAPHICS/whiteball.gif"> +Other <a href="../CONCEPT/expressions.html">operators</a> +<p> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../FUNCTIONS/malloc.html">malloc</a> function. + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/statements.html b/reference/C/SYNTAX/statements.html new file mode 100644 index 0000000..0a7439e --- /dev/null +++ b/reference/C/SYNTAX/statements.html @@ -0,0 +1,90 @@ +<title>C statements and blocks</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>C Statements and blocks.</h1> +</center> +<hr> +<h2>Statements</h2> +C has three types of statement. +<ul> +<li>assignment +<pre> + = +</pre> +<li>selection (branching) +<pre> + <a href="../EXAMPLES/if.c">if</a> (expression) + else + switch +</pre> +<li>iteration (looping) +<pre> + <a href="while.html">while</a> (expression) + <a href="for.html">for</a> (expression;expression;expression) + <a href="do.html">do</a> {block} +</pre> +</ul> + +<a name=block> +<h2>Blocks</h2> +</ul> +These statements are grouped into <i>blocks</i>, a block is identified by +curly brackets...There are two types of block. +<ul> +<li>statement blocks +<pre> + if ( i == j) + { + printf("martin \n"); + } +</pre> +The <i>statement block</i> containing the <b>printf</b> is only executed +if the <b>i == j</b> +<i>expression</i> evaluates to <a href="../CONCEPT/true_false.html">TRUE</a>.<p> + +<li>function blocks + +<pre> + int add( int a, int b) /* Function definition */ + { + int c; + c = a + b; + return c; + } +</pre> +The statements in this block will only be executed if the <i> add </i> function +is called. <a href="../EXAMPLES/function.c">Complete function example</a> + +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/static.htm b/reference/C/SYNTAX/static.htm new file mode 100644 index 0000000..273eb3a --- /dev/null +++ b/reference/C/SYNTAX/static.htm @@ -0,0 +1,175 @@ +<title>static functions</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>static functions</h1> +</center> +<hr> +<p> + +<b>static functions</b> are functions that are only visable to other +functions in the same file. Consider the following code. +<p> +<table border=2 bgcolor=ivory align=left> +<th> +main.c +</th> +<tr> +<td> +<pre> + + #include <stdio.h> + + main() + { + Func1(); + + Func2(); + } + +</pre> +</td> +</tr> +</table> + +<table border=2 bgcolor=ivory> +<th> +funcs.c +</th> +<tr> +<td> +<pre> + + /************************************* + * + * Function declarations (prototypes). + * + *************************************/ + + /* Func1 is only visable to functions in this file. */ + + <font color=red><i>static</i></font> void Func1(void); + + /* Func2 is visable to all functions. */ + + void Func2(void); + + /************************************* + * + * Function definitions + * + *************************************/ + + void Func1(void) + { + puts("Func1 called"); + } + + /*************************************/ + + void Func2(void) + { + puts("Func2 called"); + } + +</pre> +</td> +</tr> +</table> +<p> +If you attempted to compile this code with the following +command, +<p> + +<center> +<table border=2 bgcolor=ivory> +<tr> +<td> +<pre> + + gcc main.c funcs.c +</pre> +</td> +</tr> +</table> +</center> +<p> +it will fail with an error simular to..... +<p> + +<center> +<table border=2 bgcolor=ivory> +<tr> +<td> +<pre> + + undefined reference to `Func1' +</pre> +</td> +</tr> +</table> +</center> +<p> +Because 'Func1' is declared as <font color=red><i>static</i></font> +and cannot be 'seen' by 'main.c'. +<p> +<hr> +<h2>Notes:</h2> +For some reason, <font color=red><i>static</i></font> has different +meanings in in different contexts. +<ol> +<li> When specified on a function declaration, it makes the +function local to the file. +<p> +<li> When specified with a variable inside a function, it +allows the vairable to retain its value between calls to +the function. See +<a href=../CONCEPT/storage_class.html#static>static variables</a>. +</ol> +It seems a little strange that the same keyword has such +different meanings.... + +<p> +<hr> +<h2>See Also:</h2> + +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../CONCEPT/storage_class.html#static">static variables</a><p> + +<font color=brown> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../../CPLUSPLUS/SYNTAX/static.htm">C++ extensions for </a>static<p> +</font> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/storage_class.html b/reference/C/SYNTAX/storage_class.html new file mode 100644 index 0000000..c12cbc8 --- /dev/null +++ b/reference/C/SYNTAX/storage_class.html @@ -0,0 +1,187 @@ +<title>C Storage Classes</title> +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<center> +<hr> +<h1>C Storage Classes.</h1> +<hr> +</center> +<p> +C has a concept of '<i>Storage classes</i>' which are used to define the +scope (visability) and life time of variables and/or functions. +<p> +So what Storage Classes are available? +<p> +<table border=2 bgcolor=ivory> +<tr> +<td><a href="#auto">auto</a> +<td><a href="#register">register</a> +<td><a href="#static">static</a> +<td><a href="#extern">extern</a> +<td><A HREF="../SYNTAX/typedef.html">typedef</A> +</tr> +</table> +<p> +<hr> +<h2><a name="auto">auto - storage class</h2> +<b>auto</b> is the default storage class for local variables. +<pre> + { + int Count; + auto int Month; + } +</pre> + +The example above defines two variables with the same storage class. +auto can only be used within functions, i.e. local variables. <p> +<hr> +<h2><a name="register">register - Storage Class</h2> +<b>register</b> is used to define local variables that should be stored +in a register instead of RAM. This means that the variable has a maximum size +equal to the register size (usually one word) and cant have the unary '&' +operator applied to it (as it does not have a memory location). +<pre> + { + register int Miles; + } +</pre> +Register should only be used for variables that require quick access - such +as counters. It should also be noted that defining 'register' goes not mean +that the variable will be stored in a register. It means that it MIGHT be stored +in a register - depending on hardware and implimentation restrictions.<p> +<hr> +<h2><a name="static">static - Storage Class</h2> +<b>static</b> is the default storage class for global variables. The two +variables below (count and road) both have a static storage class. +<pre> + static int Count; + int Road; + + { + printf("%d\n", Road); + } +</pre> +static variables can be 'seen' within all functions in this source file. At +link time, the static variables defined here will not be seen by the object +modules that are brought in.<p> +'static' can also be defined within a function! If this is done the variable +is initalised at run time but is not reinitalized when the function is called. +This is serious stuff - tread with care. + +<pre> + { + static Count=1; + } +</pre> +Here is an <a href="../EXAMPLES/static.c">example</a><p> + +<a name="static2"> +There is one very important use for 'static'. Consider this bit of code. +<pre> + char *func(void); + + main() + { + char *Text1; + Text1 = func(); + } + + char *func(void) + { + char Text2[10]="martin"; + return(Text2); + } +</pre> + +Now, 'func' returns a pointer to the memory location where 'text2' starts +BUT text2 has a storage class of 'auto' and will disappear when we exit the +function and could be overwritten but something else. The answer is to specify +<pre> + static char Text[10]="martin"; +</pre> +The storage assigned to 'text2' will remain reserved for the duration if the +program. +<p> +<hr> +<font color=brown> +C++ has overloaded static, <a href="../../CPLUSPLUS/SYNTAX/static.htm">here +are the details.</a> +</font> +<hr> +<h2><a name="extern">extern - storage Class</h2> +<b>extern</b> defines a global variable that is visable to ALL object +modules. When you use 'extern' the variable cannot be initalized as +all it does is point the variable name at a storage location that has +been previously defined. + +<table border=2 width="80%" bgcolor="ivory"> +<th align=center> +Source 1 +</th> +<th> +Source 2 +</th> +<tr> +<td> +<pre> + +extern int count; int count=5; + +write() main() +{ { + printf("count is %d\n", count); write(); +} } +</pre> +</td> +<td> +test +</td> +</tr> +</table> + +Count in 'source 1' will have a value of 5. If source 1 changes the +value of count - source 2 will see the new value. Here are some example +source files. +<p> +<a href="../EXAMPLES/extern1.c">Source 1</a><br> +<a href="../EXAMPLES/extern2.c">Source 2</a><p> + +The compile command will look something like.<p> +<pre> + gcc source1.c source2.c -o program +</pre> + +<hr> +<h2>See Also:</h2> +<a href="../CONCEPT/data_types.html">Data types.</a> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/struct.html b/reference/C/SYNTAX/struct.html new file mode 100644 index 0000000..6465ee6 --- /dev/null +++ b/reference/C/SYNTAX/struct.html @@ -0,0 +1,392 @@ +<title>STRUCT keyword </title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center><h1>STRUCT keyword </h1></center> +<hr> +<p> + +<ul> +<li><a href="#basics">Structure basics.</a> +<li><a href="#membership">Structure membership.</a> +<li><a href="#pointers">Pointers to structures.</a> +<li><a href="#array">Array of structures.</a> +<li><a href="#geek">The bottom draw..</a> +<li><a href="../../CPLUSPLUS/SYNTAX/struct.html">C++ extensions</a> +</ul> + +<a name=basics> +<hr> +<h2>Structure basics</h2> + +<b>struct</b> is used to declare a new +<a href="../CONCEPT/data_types.html">data-type</a>. +Basically this means +grouping variables together. For example, a struct data type could be used +to declare the format of the following file.<p> + +<center> +<table border=1 bgcolor="ivory"> +<tr><td> +<pre> + Jo Loss Maths A + Harry Carpenter English A + Billy King Maths C +</pre> +</td></tr> +</table> +</center> +<p> + +The records above could be described in a struct as follows: +<p> +<center> +<table border=1 bgcolor="ivory"> +<tr><td> +<pre> + + struct + { + char cname[8]; + char sname[16]; + char exam[16]; + char grade; + } record; + +</pre> +</td></tr> +</table> +</center> +<p> +The statement above declares a variable called <b>record</b> with 4 members +called <b>cname, sname, exam, grade</b>. The structure as a whole can be +referred to as <b>record</b> and a member can be referenced as +<b>record.exam</b> +<p> + +Structures can be declared in various forms... +<p> + +<pre> + struct x {int a; int b; int c;}; /* declaration */ + struct {int a; int b; int c;} z; + struct x z; +</pre> +All the examples above are structure declarations, +<ul> +<li>The first gives <b>x</b> as a 'structure tag' - this is optional. +<li>The first and second declare the members of the structure. +<li>Second and third give <b>z</b> this is the variable that assumes the +structure type. +</ul> +<p> + +<a name=membership> +<hr> +<h2>Structure membership</h2> + +We can access individual members of a structure with the . operator.<p> +For example to assign a value, we can enter: +<p> +<center> +<table border=1 bgcolor="ivory"> +<tr><td> +<pre> + + struct x {int a; int b; int c;}; + + main() + { + struct x z; + + z.a = 10; + z.b = 20; + z.c = 30; + } + +</pre> +</td></tr> +</table> +</center> +<p> +And to retrieve a value from a structure member: +<p> +<center> +<table border=1 bgcolor="ivory"> +<tr><td> +<pre> + + struct x + { + int a; + int b; + int c; + }; + + main() + { + struct x z; + + z.a = 10; + z.a++; + + printf(" first member is %d \n", z.a); + } + +</pre> +</td></tr> +</table> +</center> +<p> +<a name=pointers> +<hr> +<h2>Pointers to structures</h2> + +<a href="#arrow">Fast path to an explanation of the -> operator.</a> +<p> + +All that we have discussed so far has been OK but runs into problems +when structures have to be moved between functions for the following +reasons. +<ul> +<li>If the structure is large it is more effiecent to pass a +<a href="../CONCEPT/pointers.html">pointer</a> to the structure +instead of the structure its self. This technic is also used to pass +<a href="../CONCEPT/pointers.html#arrays">pointers to arrays</a> between +<a href="functions.html#2.5">functions.</a> +<p> +<li>When passing a structure to a function, you actually pass a COPY of the +structure. Therefore it is not possible to change the values of members +within the structure as the copy is destroyed when the function ends. +</ul> +<p> +So how does it all work? Here is an example. (make your browser W-I-D-E so +you can see the two examples). +<p> +<center> +<table border=1 bgcolor="ivory"> +<tr><td> +<pre> + | + | + struct x {int a; int b; int c;} ; | struct x {int a; int b; int c;} ; + | + void function(struct x); | void function(struct x *); + | + main() | main() + { | { + struct x z; | struct x z, *pz; <font color=red>/* 3 */</font> + | pz = &z; <font color=red>/* 4 */</font> + z.a = 10; <font color=red>/* 1 */</font> | z.a = 10; + z.a++; | z.a++; + | + function(z); <font color=red>/* 2 */</font> | function(pz); <font color=red>/* 5 */</font> + } | } + | + void function( struct x z) | void function(struct x * pz) + { | { <font color=red>/* 6 */</font> + printf(" first member %d \n", z.a);| printf(" first member %d \n", (*pz).a); + } | } + | +</pre> +</td></tr> +</table> +</center> +<p> +Here is the annotation. +<ol> +<li>Give a structure member a value. +<li>Pass a COPY of the whole structure to the function. +<li>Define 'pz' a pointer to a structure of type 'x'. +<li>Put the address of 'z' into 'pz'. 'pz' now POINTS to 'z'. +PLEASE NOTE. 'z' is defined to reserve memory equal to the size of the +structure. 'pz' only holds an address so will be 4 bytes long. +<li>Pass the pointer into the function. +<li>Print the value of the member 'a'. +</ol> + +<a name=arrow> +The <b>(*pz).a</b> syntax is used a great deal in C and it was decided to create +a short hand for it. So: + +<pre> + (*pz).a == pz->a +</pre> + +Here is the final picture. +<pre> + + /*************************************************************************/ + + struct x {int a; int b; int c;} ; /* Declare the structure. */ + + void function(struct x * ); /* Declare the function. */ + + /*************************************************************************/ + + main() + { + /* Declare two variables. + * z == type struct x + * pz == a pointer to type struct x + */ + struct x z, *pz; + + pz = &z; /* put the address of 'z' into 'pz' */ + z.a = 10; /* initialize z.a */ + z.a++; /* Increment z.a */ + + /* print the contents of 'z.a' + * using the pointer 'pz' */ + + printf(" first member before the function call %d \n", pz->a); + + /* Call 'function' passing the + * pointer 'pz' */ + function(pz); + + /* Print the NEW value of 'z.a' + * using three different notations */ + printf(" first member after the function call %d \n", pz->a); + printf(" first member after the function call %d \n", (*pz).a); + printf(" first member after the function call %d \n", z.a); + + } + + /*************************************************************************/ + + void function(struct x * pz) + { + /* Print the value of 'z.a' by + * referencing the pointer 'pz' + * which holds the address of 'z' */ + printf(" first member inside the function %d \n", pz->a); + + /* Increment the value of 'z.a' + * this is the source location + * in memory. */ + pz->a++; + + } + + /*************************************************************************/ + + +</pre> + +<a name=geek> +<p> +<hr> +<h2>The Bottom Draw</h2> + +Finally, here is a little feature that allows you to save a little +space. +<p> +<center> +<table border=1 bgcolor="ivory"> +<tr><td> +<pre> + + main() + { + struct Flags + { + unsigned int Online <font color=red>:1</font>; + unsigned int Mounted <font color=red>:1</font>; + } + + struct Flags TapeInfo; + + TapeInfo.Online = 1; + TapeInfo.Mounted = 0; + } + +</pre> +</td></tr> +</table> +</center> +<p> +The <font color=red>:1</font> tells the compiler that only 1 byte is +required for <b>Online</b> and <b>Mounted</b>. There are a few points to +note about this though. +<ul> +<li>You may expect the compiler to reserve 2 bytes for the structure, it +actually reserves one word (usually 4 bytes) as this is the smallest unit +that can be reserved, the remaining 2 bytes are unavailable. +This is still better than the 2 words that wold normally get reserved. +<li>You can put any number into the variable, if the number is too large +to fit, the high order bits are lost without warning. +<li>Only <b>signed int</b>, <b>unsigned int</b>, <b>int</b> support this syntax. +</ul> +<hr> + +<h2>Examples</h2> +<p> +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/struct1.c"> +This is the most basic <b>struct</b> example I could think of.</a> +<br> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/struct2.c"> +Using structure elements, and passing them into a function.</a> +<br> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/struct3.c"> +Passing a whole structure to a function.</a> This performs a copy of the +structure so the same rules apply as for <b>int</b> etc. +Pointers to structures can be passed but I have not got to them yet.... +<br> + +<a name=array> +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/struct4.c">Define and use an array of structures.</a> +<br> + +<img src=../../GRAPHICS/help.gif> +<a href="../PROBLEMS/problems.html#struct"> +Here is a <b>struct</b> problem for you.</a> + + + +<hr> +<h2>See Also:</h2> +<img src=../../GRAPHICS/whiteball.gif> +<a href="typedef.html">typedef</a> keyword. +<br> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../MISC/linklists.html">Linked lists</a>. +<br> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/switch.html b/reference/C/SYNTAX/switch.html new file mode 100644 index 0000000..7fb870f --- /dev/null +++ b/reference/C/SYNTAX/switch.html @@ -0,0 +1,233 @@ +<title>switch/case keywords</title> + +<head> +<script language="JavaScript"> +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>The 'switch' and 'case' keywords</h1> +</center> +<hr> +<p> + +The <b>switch-case</b> statement is a multi-way decision statement. Unlike the +multiple decision statement that can be created using +<a href=if.html>if-else</a>, the <b>switch</b> +statement evaluates the conditional +<a href="../CONCEPT/expressions.html">expression</a> and tests it against +numerous +<a href="../CONCEPT/constants.html">constant</a> +values. The branch corresponding to the value that the +expression matches is taken during execution. +<p> +The value of the expressions in a switch-case statement must be an ordinal +type i.e. +<a href="../CONCEPT/data_types.html">integer, char, short, long</a>, +etc. Float and double are not +allowed. +<p> +The syntax is : +<p> +<center> +<table bgcolor="ivory"> +<tr> +<td> +<pre> + + switch( expression ) + { + case constant-expression1: statements1; + [case constant-expression2: statements2;] + [case constant-expression3: statements3;] + [default : statements4;] + } +</pre> +</td> +</tr> +</table> +</center> +<p> + +The <b>case</b> statements and the <b>default</b> statement can occur in any +order in +the <b>switch</b> statement. The <b>default</b> clause is an optional clause +that is +matched if none of the constants in the <b>case</b> statements can be matched. +<p> +Consider the example shown below: +<p> +<center> +<table bgcolor="ivory"> +<tr> +<td> +<pre> + + switch( Grade ) + { + case 'A' : printf( "Excellent" ); + case 'B' : printf( "Good" ); + case 'C' : printf( "OK" ); + case 'D' : printf( "Mmmmm...." ); + case 'F' : printf( "You must do better than this" ); + default : printf( "What is your grade anyway?" ); + } +</pre> +</td> +</tr> +</table> +</center> +<p> + +Here, if the Grade is 'A' then the output will be +<p> +<center> +<table bgcolor="ivory"> +<tr> +<td> +<pre> + Excellent + Good + OK + Mmmmm.... + You must do better than this + What is your grade anyway? +</pre> +</td> +</tr> +</table> +</center> +<p> + +This is because, in the 'C' <b>switch</b> statement, execution continues on into +the next case clause if it is not explicitly specified that the execution +should exit the <b>switch</b> statement. The correct statement would be: +<p> +<center> +<table bgcolor="ivory"> +<tr> +<td> +<pre> + + switch( Grade ) + { + case 'A' : printf( "Excellent" ); + break; + + case 'B' : printf( "Good" ); + break; + + case 'C' : printf( "OK" ); + break; + + case 'D' : printf( "Mmmmm...." ); + break; + + case 'F' : printf( "You must do better than this" ); + break; + + default : printf( "What is your grade anyway?" ); + break; + } +</pre> +</td> +</tr> +</table> +</center> +<p> + +Although the <b>break</b> in the <b>default</b> clause (or in general, after +the last +clause) is not necessary, it is good programming practice to put it in +anyway. +<p> +An example where it is better to allow the execution to continue into the +next <b>case</b> statement: +<p> +<center> +<table bgcolor="ivory"> +<tr> +<td> +<pre> + + char Ch; + . + . + switch( Ch ) + { + /* Handle lower-case characters */ + case 'a' : + case 'b' : + . + . + . + case 'z' : + printf( "%c is a lower-case character.\n", Ch ); + printf( "Its upper-case is %c.\n" toupper(Ch) ); + break; + + /* Handle upper-case characters */ + case 'A' : + case 'B' : + . + . + . + case 'Z' : + printf( "%c is a upper-case character.\n", Ch ); + printf( "Its lower-case is %c.\n" tolower(Ch) ); + break; + + /* Handle digits and special characters */ + + default : + printf( "%c is not in the alphabet.\n", Ch ); + break; + + } + . + . +</pre> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<h2>Example:</h2> +<img src="../../GRAPHICS/computer.gif" align=center> +<a href=../EXAMPLES/switch.c>Basic <b>switch</b> example.</a> +<br clear=left> +<hr> +<h2>See also:</h2> +<ul> +<li><a href=if.html>if keyword</a>. +</ul> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/syntax.gif b/reference/C/SYNTAX/syntax.gif Binary files differnew file mode 100644 index 0000000..737bb1f --- /dev/null +++ b/reference/C/SYNTAX/syntax.gif diff --git a/reference/C/SYNTAX/syntax.html b/reference/C/SYNTAX/syntax.html new file mode 100644 index 0000000..7dcfce4 --- /dev/null +++ b/reference/C/SYNTAX/syntax.html @@ -0,0 +1,135 @@ +<html> +<head> +<title>C Syntax</title> +<script language="JavaScript"> + +agent = navigator.userAgent + +browserVer = 2 + +if (agent.indexOf("a/3",6) == -1) +{ + browserVer = 2 +} +else +{ + browserVer = 1 +} +if (agent.indexOf("a/3",6) == -1) +{ + browserVer = 2 +} +else +{ + browserVer = 1 +} + +if (browserVer == 1) +{ + Active = new Image(26,14); + Active.src = "../../GRAPHICS/redball.gif" + NotActive = new Image(26,14); + NotActive.src = "../../GRAPHICS/whiteball.gif" +} + +// ................................................................... + +function Blob(Href, Name, Str) +{ + Text = "<img src=../../GRAPHICS/whiteball.gif width=26 height=14 alt=\"o\" name=\"" + Name + "\">"; + Text += "<a href=\"" + Href + "\" onmouseover=\"HiLite('" + Name + "', 'Active')\""; + Text += " onmouseout=\"HiLite('" + Name + "', 'NotActive')\">" + Str + "</a>"; + + document.write(Text); +} + +// ................................................................... + +function HiLite(imgDocID, NewImage) +{ + if (browserVer == 1) + { + document.images[imgDocID].src = eval(NewImage + ".src") + } +} + +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<img src="../../GRAPHICS/syntax.gif" alt="Syntax"> +</center> +<hr> +<p> +The following items highlight the main areas of C syntax. +<p> +<hr> +<font size=-1> +If nothing appears below this line, +<a href=syntax_p.html>click on low tech links.</a> +</font> +<hr> +<dl> +<dt><script>Blob("keywords.html", "A", " C Keywords.");</script> +<dt><script>Blob("../../CPLUSPLUS/SYNTAX/keywords.html","B", " C++ Keywords.");</script> +<dt><script>Blob("comments.html", "C", " Comments.");</script> +<dt><script>Blob("../CONCEPT/constants.html", "D", " Constants.");</script> +<dt><script>Blob("../CONCEPT/expressions.html", "E", " Expressions/Operators.");</script> +<dt><script>Blob("../CONCEPT/precedence.html", "F", " Operator Precedence.");</script> +<dt><script>Blob("statements.html", "G", " Statements and blocks.");</script> +<p> + +<dt><script>Blob("glo_int_vars.html", "H", " Global and local variable declaration.");</script> +<dt><script>Blob("../CONCEPT/data_types.html", "I", " Variable declaration - data types.");</script> +<dt><script>Blob("../CONCEPT/type_conv.html", "J", " Data type conversion.");</script> +<dt><script>Blob("../CONCEPT/storage_class.html", "K", " Variable declaration - Storage Class.");</script> +<dt><script>Blob("../CONCEPT/cast.html", "L", " cast.");</script> +<dt><script>Blob("../CONCEPT/true_false.html", "M", " TRUE and FALSE.");</script> +<p> + +<dt><script>Blob("../CONCEPT/arrays.html", "N", " Arrays.");</script> +<dt><script>Blob("../CONCEPT/pointers.html", "O", " Pointers.");</script> +<dt><script>Blob("struct.html", "P", " Structures.");</script> +<dt><script>Blob("../MISC/linklists.html", "Q", " Linklists.");</script> +<p> + +<dt><script>Blob("../CONCEPT/bitwise.html", "R", " Bitwise operations.");</script> +<p> + +<dt><script>Blob("preprocessors.html", "S", " Preprocessors.");</script> +<dt><script>Blob("macros.html", "T", " Macros.");</script> +<p> + +<dt><script>Blob("idioms.html", "U", " Idioms.");</script> +<p> +<dt><script>Blob("functions.html", "V", " Functions - passing and returning arguments.");</script> +<dt><script>Blob("../FUNCTIONS/funcref.htm", "W", " Function Quick Reference.");</script> + +</dl> + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/syntax_p.html b/reference/C/SYNTAX/syntax_p.html new file mode 100644 index 0000000..1c3d11d --- /dev/null +++ b/reference/C/SYNTAX/syntax_p.html @@ -0,0 +1,110 @@ +<!doctype html public "-//w3c//dtd html 4.0 transitional//en"> +<html> +<head> + <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> + <meta name="GENERATOR" content="Mozilla/4.5 [en] (X11; I; Linux 2.0.36 i586) [Netscape]"> + <title>C Syntax</title> +</head> +<body bgcolor="#FFFFCC"> + +<hr> +<center><img SRC="syntax.gif" height=54 width=221></center> + +<hr> +<p>The following items highlight the main areas of C syntax. +<p> +<hr><font size=-1>If your browser can support JavaScript <a href="syntax.html">click +here.</a></font> +<hr> +<ul> +<li> +<a href="keywords.html">C Keywords.</a></li> + +<li> +<a href="../../CPLUSPLUS/SYNTAX/keywords.html">C++ Keywords.</a></li> + +<li> +<a href="comments.html">Comments.</a></li> + +<li> +<a href="../CONCEPT/constants.html">Constants.</a></li> + +<li> +<a href="../CONCEPT/expressions.html">Expressions.</a></li> + +<li> +<a href="../CONCEPT/precedence.html">Operator Precedence.</a></li> + +<li> +<a href="statements.html">Statements and blocks.</a></li> + +<li> +<a href="glo_int_vars.html">Global and local variable declaration.</a></li> + +<li> +<a href="../CONCEPT/data_types.html">Variable declaration - data types.</a></li> + +<li> +<a href="../CONCEPT/type_conv.html">Data type conversion.</a></li> + +<li> +<a href="../CONCEPT/storage_class.html">Variable declaration.</a></li> + +<li> +<a href="../CONCEPT/cast.html">cast.</a></li> + +<li> +<a href="../CONCEPT/true_false.html">TRUE and FALSE.</a></li> + +<li> +<a href="../CONCEPT/arrays.html">Arrays.</a></li> + +<li> +<a href="../CONCEPT/pointers.html">Pointers.</a></li> + +<li> +<a href="struct.html">Structures.</a></li> + +<li> +<a href="../MISC/linklists.html">Linklists.</a></li> + +<li> +<a href="../CONCEPT/bitwise.html">Bitwise operations.</a></li> + +<li> +<a href="preprocessors.html">Preprocessors.</a></li> + +<li> +<a href="macros.html">Macros</a></li> + +<li> +<a href="idioms.html">Idioms.</a></li> + +<li> +<a href="functions.html">Functions - passing and returning arguments.</a></li> + +<li> +<a href="../FUNCTIONS/funcref.htm">Function Quick Reference.</a></li> +</ul> + +<hr> +<center><table BORDER=2 WIDTH="80%" BGCOLOR="#FFFFF0" > +<tr ALIGN=CENTER> +<td WIDTH="25%"><a href="../cref.html">Top</a></td> + +<td WIDTH="25%"><a href="../master_index.html">Master +Index</a></td> + +<td WIDTH="25%"><a href="keywords.html">Keywords</a></td> + +<td WIDTH="25%"><a href="../FUNCTIONS/funcref.htm">Functions</a></td> +</tr> +</table></center> + +<p> +<hr> +<address> +Martin Leslie</address> + +</body> +</html> diff --git a/reference/C/SYNTAX/typedef.html b/reference/C/SYNTAX/typedef.html new file mode 100644 index 0000000..e9cb665 --- /dev/null +++ b/reference/C/SYNTAX/typedef.html @@ -0,0 +1,140 @@ +<html> +<head> +<title>The TYPEDEF keyword.</title> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The TYPEDEF keyword.</h1></center> +<hr> +<p> +Every variable has a +<a href="../CONCEPT/data_types.html">data type</a>. <b>typedef</b> is used to define +new data type names to make a program more readable to the programmer. +<p> +For example: +<p> +<table border=1 width="100%" bgcolor="ivory"> +<tr><td> +<pre> + + | + main() | main() + { | { + int money; | typedef int Pounds; + money = 2; | Pounds money = 2 + } | } +</pre> +</td></tr></table> +<p> +These examples are EXACTLY the same to the compiler. But the right hand +example tells the programmer the type of money he is dealing with. +<p> +<a name=boolean></a> +A common use for typedef is to define a boolean data type as below. +<font color="brown"> +<br> +Note: Recent C++ compilers have introduced a <a href="../../CPLUSPLUS/SYNTAX/bool.html">boolean</a> datatype. +<p> +</font> +<p> +<table border=1 width="100%" bgcolor="ivory"> +<tr><td> +<pre> + + typedef enum {FALSE=0, TRUE} Boolean + + main () + { + Boolean flag = TRUE; + } + +</pre> +</td></tr></table> +<p> + +And as a final example, how about creating a string datatype? +<p> +<table border=1 width="100%" bgcolor="ivory"> +<tr><td> +<pre> + + typedef char *String; + + main() + { + String Text = "Thunderbird"; + + printf("%s\n", Text); + } + +</pre> +</td></tr></table> +<p> + +The main use for typedef seems to be defining +<a href="struct.html">structures</a>. For example: +<p> +<table border=1 width="100%" bgcolor="ivory"> +<tr><td> +<pre> + + typedef struct {int age; char *name} person; + person people; + +</pre> +</td></tr></table> +<p> + +Take care to note that <b>person</b> is now a type specifier and NOT a +variable name. +<p> +As a final note, you can create several data types in one hit. +<table border=1 width="100%" bgcolor=ivory> +<tr><td> +<pre> + + + typedef int Pounds, Shillings, Pennies, Dollars, Cents; + +</pre> +</td></tr></table> +<p> + +<p> +<hr> +<h2>Examples:</h2> +<img src="../../GRAPHICS/computer.gif" align=center> +<a href="../EXAMPLES/linklst3.c">Here is a rather heavy example of typedef.</a> +<br clear=left> +<hr> +<h2>Notes:</h2> +I would expect to see 'typedef' in header files. + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> + diff --git a/reference/C/SYNTAX/union.html b/reference/C/SYNTAX/union.html new file mode 100644 index 0000000..5334e3b --- /dev/null +++ b/reference/C/SYNTAX/union.html @@ -0,0 +1,89 @@ +<title>The UNION keyword.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The UNION keyword.</h1></center> +<hr> + +The <b>union</b> <a href="../glossary.html#keyword">keyword</a> allows several +variables of different type and size to occupy the same storage location. +<p> +The syntax to define a union is simular to the +<a href="struct.html">struct</a> keyword as shown below:<p> + + +<pre> + union union_def { int a; float b; char c;} ; +</pre> + +and a variable declared with either of these statements: + +<pre> + union union_def union_var; + union { int a; float b; char c;} union_var; +</pre> + +If you wish to initalise a variable you can say: + +<pre> + union { int a; float b; char c;} union_var=97; +</pre> + +By default the first variable (<b>a</b>) is initalised. +<p> + +To assign a value to a variable you can say: + +<pre> + union_var.b=99.99; + union_var.a=34; + union_var.c='x'; +</pre> +It's important to note that the storage will only hold ONE value, +looking at the +three lines above, <b>union_var.a</b> overwrites <b>union_var.b</b> and +then <b>union_var.c</b> overwrites <b>union_var.a</b><p> + + + +I have yet to see more than one use for this keyword. +<hr> +<h2>Examples:</h2> +<img src="../../GRAPHICS/computer.gif" align=left> +<a href="../EXAMPLES/union.c"> Here is an example.</a> +<br clear=left> +<hr> +<h2>See also:</h2> +<ul> +<li><a href="struct.html">struct</a> keyword. +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/void.html b/reference/C/SYNTAX/void.html new file mode 100644 index 0000000..51c5b03 --- /dev/null +++ b/reference/C/SYNTAX/void.html @@ -0,0 +1,104 @@ +<title>The VOID keyword.</title> +<head> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The VOID keyword.</h1></center> +<hr> +<p> +The <b>void</b> <a href="../glossary.html#keyword">keyword</a> +allows us to create functions that either do not require any +parameters or do not return a value.<p> +The following example shows a function that does not return +a value. +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + void Print_Square(int Number); + + main() + { + Print_Square(10); + exit(0); + } + + void Print_Square(int Number) + { + printf("%d squared is %d\n",Number, Number*Number); + } +</pre> +</td> +</tr> +</table> +<p> +The next example shows a function that does not require any parameters: +<p> +<table border=2 width="100%" bgcolor=ivory> +<tr> +<td> +<pre> + + #include <stdlib.h> + #include <time.h> + + int Random(void); + + main() + { + printf("A random number is %d\n", Random()); + exit(0); + } + + int Random(void) + { + srand((unsigned int)time((time_t *)NULL)); + return( rand()); + } + +</pre> +</td> +</tr> +</table> +<p> +<hr> +<h2>Example:</h2> +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/pointer_func.c">void example</a> +<hr> +<h2>See also:</h2> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../SYNTAX/functions.html">Functions</a> +<a href="../SYNTAX/functions.html#void">Void pointers</a> +<p> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/volatile.html b/reference/C/SYNTAX/volatile.html new file mode 100644 index 0000000..1de9b13 --- /dev/null +++ b/reference/C/SYNTAX/volatile.html @@ -0,0 +1,97 @@ +<html> +<head> +<title>The VOLATILE keyword.</title> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The VOLATILE keyword.</h1></center> +<hr> +I have had several sugestions on how to describe volatile, +If you have any input please mail me. +<ul> +<li>The <b>volatile</b> <a href="../glossary.html#keyword">keyword</a> acts as a +<a href="../CONCEPT/data_types.html">data type</a> qualifier. +The qualifier alters the default why in which +the compiler handles the variable and does not attempt to optimize the +storage referenced by it. <i>Martin Leslie</i> +<p> +<li><b>volatile</b> means the storage is likely to change at anytime +and be changed but something outside the control of the user program. +This means that if you reference the variable, +the program should always check the physical address (ie a mapped input fifo), +and not use it in a cashed way.<i>Stephen Hunt</i> +<p> +<li>Here is an example for the usage of the volatile keyword: +<pre> + /* Base address of the data input latch */ + + volatile unsigned char *baseAddr; + + /* read parts of output latch */ + + lsb = *handle->baseAddr; + middle = *handle->baseAddr; + msb = *handle->baseAddr; +</pre> +Between reads the bytes are changed in the latch. +<p> +Without the volatile, the compiler optimises this to a single assignment: +<pre> + lsb = middle = msb = *handle->baseAddr; +</pre> +<i>Tim Potter</i> +<p> +<li>A <b>volatile</b> variable is for dynamic use. E.G. for data that is to +be passed to an I/O port Here is an example. + +<pre> + #define TTYPORT 0x17755U + + volatile char *port17 = (char)*TTYPORT; + *port17 = 'o'; + *port17 = 'N'; +</pre> +Without the <b>volatile</b> modifier, the compiler would think that the +statement <code>*port17 = 'o';</code> is redundant and would remove it +from the object code. The volatile statement prevents the compiler +optimisation.<i>Alex Arzon</i>. +</ul> + +<hr> +<h2>Examples:</h2> +<img src="../../GRAPHICS/computer.gif" align=left alt="o"> No example:-( +<br clear=left> +<hr> +<h2>See also:</h2> +<ul> +<li><a href="../CONCEPT/data_types.html#qualifier">const qualifier</a> +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> diff --git a/reference/C/SYNTAX/while.html b/reference/C/SYNTAX/while.html new file mode 100644 index 0000000..ef083f9 --- /dev/null +++ b/reference/C/SYNTAX/while.html @@ -0,0 +1,160 @@ +<html> +<head> +<title>The WHILE keyword.</title> +<script language="JavaScript"> +</script> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>The WHILE keyword.</h1></center> +<hr> +The <b>while</b> keyword is related to <a href=do.html>do</a> +and <a href=for.html>for</a>. Its purpose is to repeatedly execute +a <a href="statements.html#blocks">block</a> of statements. Here is +an example : + +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr> +<td> +<pre> + + main() + { + int i=5; + + while(--i) + { + printf(" i is %d\n", i); + } + } +</pre> +</td> +</tr> +</table> +</center> +<p> + +The expression <b>i--</b> is evaluated and if its +<a href="../CONCEPT/true_false.html">true</a> the statements in the +<a href="statements.html#blocks">block</a> are executed. +The loop continues until the expression is false (zero). +The result will look like this: + +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr> +<td> +<pre> + + i is 4 + i is 3 + i is 2 + i is 1 +</pre> +</td> +</tr> +</table> +</center> +<p> + +It is important to note that the statements +on a <b>while</b> will not get executed if the first evaluation of the +expression is FALSE. If you do not want this to happen you may prefer +to use the <a href="do.html">do</a> statement. + +<hr> +<p> +Now consider the next example. + +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr> +<td> +<pre> + + main() + { + int i=5; + + while(--i); + { + printf(" i is %d\n", i); + } + } +</pre> +</td> +</tr> +</table> +</center> + + +The result will look like this: + + +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr> +<td> +<pre> + + i is 0 +</pre> +</td> +</tr> +</table> +</center> + +<p> +This is because of the <b>;</b> on the end of the <b>while</b> +statement which means the <b>while</b> will loop (executing NULL statements) +until <b>i</b> is zero. Execution will then continue down the program +(to the printf). +<p> + +<hr> +<h2>Examples:</h2> + +<img src="../../GRAPHICS/computer.gif" align=left alt="o"> +<a href="../EXAMPLES/while.c">Basic <b>while</b></a>. +<br clear=left> + +<hr> +<h2>See also:</h2> +<ul> +<li><a href="while.html">for</a> keyword. +<li><a href="do.html">do</a> keyword. +<li><a href="break.html">break</a> keyword. +<li><a href="continue.html">continue</a> keyword. +</ul> + + +<p> + +<hr> +<p> +<center> +<table border=2 width="80%" bgcolor="ivory"> +<tr align=center> +<td width="25%"> +<a href="../cref.html"> Top</a> +</td><td width="25%"> +<a href="../master_index.html"> Master Index</a> +</td><td width="25%"> +<a href="keywords.html"> Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm"> Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +</address><p> +</body> +</html> |