From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/SYNTAX/Makefile.am | 5 + reference/C/SYNTAX/Makefile.in | 410 +++++++++++++++++++++++++++ reference/C/SYNTAX/Master.html | 54 ++++ reference/C/SYNTAX/break.html | 54 ++++ reference/C/SYNTAX/comma.html | 60 ++++ reference/C/SYNTAX/comments.html | 111 ++++++++ reference/C/SYNTAX/conditional.html | 120 ++++++++ reference/C/SYNTAX/const.html | 212 ++++++++++++++ reference/C/SYNTAX/continue.html | 46 +++ reference/C/SYNTAX/define_preprocessor.html | 77 +++++ reference/C/SYNTAX/do.html | 81 ++++++ reference/C/SYNTAX/enum.html | 97 +++++++ reference/C/SYNTAX/for.html | 175 ++++++++++++ reference/C/SYNTAX/fork1.c | 24 ++ reference/C/SYNTAX/functions.html | 138 +++++++++ reference/C/SYNTAX/glo_int_vars.html | 214 ++++++++++++++ reference/C/SYNTAX/got_ya.html | 80 ++++++ reference/C/SYNTAX/goto.html | 59 ++++ reference/C/SYNTAX/idioms.html | 136 +++++++++ reference/C/SYNTAX/if.html | 133 +++++++++ reference/C/SYNTAX/include_preprocessor.html | 61 ++++ reference/C/SYNTAX/keywords.html | 115 ++++++++ reference/C/SYNTAX/logical.html | 102 +++++++ reference/C/SYNTAX/macros.html | 96 +++++++ reference/C/SYNTAX/namespace.html | 46 +++ reference/C/SYNTAX/null.html | 81 ++++++ reference/C/SYNTAX/preprocessors.html | 83 ++++++ reference/C/SYNTAX/return.html | 134 +++++++++ reference/C/SYNTAX/sizeof.html | 130 +++++++++ reference/C/SYNTAX/statements.html | 90 ++++++ reference/C/SYNTAX/static.htm | 175 ++++++++++++ reference/C/SYNTAX/storage_class.html | 187 ++++++++++++ reference/C/SYNTAX/struct.html | 392 +++++++++++++++++++++++++ reference/C/SYNTAX/switch.html | 233 +++++++++++++++ reference/C/SYNTAX/syntax.gif | Bin 0 -> 888 bytes reference/C/SYNTAX/syntax.html | 135 +++++++++ reference/C/SYNTAX/syntax_p.html | 110 +++++++ reference/C/SYNTAX/typedef.html | 140 +++++++++ reference/C/SYNTAX/union.html | 89 ++++++ reference/C/SYNTAX/void.html | 104 +++++++ reference/C/SYNTAX/volatile.html | 97 +++++++ reference/C/SYNTAX/while.html | 160 +++++++++++ 42 files changed, 5046 insertions(+) create mode 100644 reference/C/SYNTAX/Makefile.am create mode 100644 reference/C/SYNTAX/Makefile.in create mode 100644 reference/C/SYNTAX/Master.html create mode 100644 reference/C/SYNTAX/break.html create mode 100644 reference/C/SYNTAX/comma.html create mode 100644 reference/C/SYNTAX/comments.html create mode 100644 reference/C/SYNTAX/conditional.html create mode 100644 reference/C/SYNTAX/const.html create mode 100644 reference/C/SYNTAX/continue.html create mode 100644 reference/C/SYNTAX/define_preprocessor.html create mode 100644 reference/C/SYNTAX/do.html create mode 100644 reference/C/SYNTAX/enum.html create mode 100644 reference/C/SYNTAX/for.html create mode 100644 reference/C/SYNTAX/fork1.c create mode 100644 reference/C/SYNTAX/functions.html create mode 100644 reference/C/SYNTAX/glo_int_vars.html create mode 100644 reference/C/SYNTAX/got_ya.html create mode 100644 reference/C/SYNTAX/goto.html create mode 100644 reference/C/SYNTAX/idioms.html create mode 100644 reference/C/SYNTAX/if.html create mode 100644 reference/C/SYNTAX/include_preprocessor.html create mode 100644 reference/C/SYNTAX/keywords.html create mode 100644 reference/C/SYNTAX/logical.html create mode 100644 reference/C/SYNTAX/macros.html create mode 100644 reference/C/SYNTAX/namespace.html create mode 100644 reference/C/SYNTAX/null.html create mode 100644 reference/C/SYNTAX/preprocessors.html create mode 100644 reference/C/SYNTAX/return.html create mode 100644 reference/C/SYNTAX/sizeof.html create mode 100644 reference/C/SYNTAX/statements.html create mode 100644 reference/C/SYNTAX/static.htm create mode 100644 reference/C/SYNTAX/storage_class.html create mode 100644 reference/C/SYNTAX/struct.html create mode 100644 reference/C/SYNTAX/switch.html create mode 100644 reference/C/SYNTAX/syntax.gif create mode 100644 reference/C/SYNTAX/syntax.html create mode 100644 reference/C/SYNTAX/syntax_p.html create mode 100644 reference/C/SYNTAX/typedef.html create mode 100644 reference/C/SYNTAX/union.html create mode 100644 reference/C/SYNTAX/void.html create mode 100644 reference/C/SYNTAX/volatile.html create mode 100644 reference/C/SYNTAX/while.html (limited to 'reference/C/SYNTAX') 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 @@ +XXX + + + + + + +
+
+

XXXX

+
+
+XXXX +

+


+ +
+

Examples:

+ + example +program. + +
+

See Also:

+ + +malloc function.

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ +The break statement + + + + + + +


+
+

The break statement.

+
+
+

+This statement allows the program to escape from for, +while, +do ... while loops and switch structures. +

+ +It should NOT be used to escape from an if block. +

+ +


+

Examples

+ + + + Switch example. + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ +The COMMA. + + + + +


+

The COMMA.

+
+The comma has two uses. The most comman, is as a parameter seperator +for data types and +function parameter lists. +Here is an example: +
+	main()
+    	{
+	   char String1[20], String2[]="Outback Pub"; /* data types */
+	   strncpy(String1, string2, 7);
+	}
+
+The other use is as a series operator which can be seen in use with +the for keyword. An example of the syntax is shown +in the link below. + +
+

Examples:

+ + +Example of the series operator. + +
+

See also:

+ +Nothing else to see :-( + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + +Comments. + + + + +


+
+

Comments.

+
+
+

+Lets start with a few examples. +

+

+ + + + +
+
+
+  main()
+  {
+
+      int Counter=0;       /* Initalise Counter */
+
+      /* a comment */
+
+      /*
+       * Another comment
+       */
+
+      /*****************
+       *
+       * Final comment.
+       *
+       *****************/ 
+  }
+
+
+
+

+


+

+A comment starts with a /* and +ends with */. Comments started in this way can span multiple +lines but cannot be nested. +For example: +

+

+ + + + +
+
+
+   main()
+   {
+       int Count = 0;           /* Initalise 
+                                 * Counter to 0 */
+
+       /* /* Invalid comment */ */
+   }
+
+
+
+

+This will give a syntax error, because the last line +contains nested comments. + +C++ offers a solution to +comment nesting. + +

+ +


+ +

C++ Extension

+ +
Inline comments + +

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +Conditional Expressions + + + + + + +


+
+

Conditional Expressions.

+
+
+

+ + +We have a short-hand construct for some if ... else ... constructs.

+Consider the following two examples. +

+

+ + + + + + + +
Example 1Example 2
+
+
+  if ( x == 1 ) 
+    y = 10;
+  else
+    y = 20;
+    
+
+
+
+
+  y = (x == 1) ? 10 : 20;  
+
+
+
+
+

+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 true evaluates the second '10'. If false the +third is evaluated. Here is another example. +

+

+ + + + + + + +
Example 1Example 2
+
+
+ if ( x == 1 ) 
+   puts("take car"); 
+ else
+   puts("take bike");  
+
+
+
+
+ (x == 1) ? puts("take car") : puts("take bike"); 
+                                                  
+    or
+
+ puts( (x == 1) ? "take car" : "take bike");
+
+
+
+

+It has been said that the compiler can create more efficent code from +a conditional expression 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 ;-) +

+


+

See also:

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ + +The const keyword. + + + + + +


+
+

The const keyword.

+
+
+ +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. + +

const syntax

+

+

+ + +
+
+
+        main()
+        {
+            const float pi = 3.14; 
+        }
+
+
+
+

+The const keyword is used as a qualifier to the following data types - +int float char double struct. +

+

+ + +
+
+
+        const int   degrees = 360; 
+        const float pi      = 3.14; 
+        const char  quit    = 'q'; 
+
+
+
+

+

const and pointers.

+ +Consider the following example. +

+

+ + +
+
+
+        void Func(const char *Str);
+
+        main()
+        {
+            char *Word;
+
+            Word = (char *) malloc(20);
+
+            strcpy(Word, "Sulphate");
+          
+            Func(Word);
+        }
+        
+        void Func(const char *Str)
+        {
+        }
+
+
+
+

+The const char *Str tells the compiler that the DATA the +pointer points too is const. 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.... + +

+

+ + +
+
+
+            --------
+           | Str    |  Value can be changed
+            -----|--
+                 |
+                 |
+                 V
+            --------
+           | *Str   | Read Only - Cannot be changed.
+            --------
+
+
+
+

+ +

Geeky Stuff

+ +It is still possible to change the contents of a 'const' variable. +Consider this program it creates +a const variable and then changes its value by accessing the data by +another name. +

+I am not sure if this applies to all compilers, but, +you can place the 'const' after the datatype, for example: +

+

+ + +
+
+
+        int   const degrees = 360; 
+        float const pi      = 3.14; 
+        char  const quit    = 'q'; 
+
+ +
+
+

+are all valid in 'gcc'. +

+

More Geeky Stuff

+ +What would you expect these to do? +

+

+ + +
+
+
+        main()
+        {
+            const char * const Variable1;
+            char const * const Variable2;
+        };
+
+
+
+

+These both make the pointer and the data read only. +Here are a few more examples. +

+

+ + +
+
+
+  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. */  
+                           
+
+
+
+

+ +


+

See Also.

+o +#define preprocessor +

+ +o +C++ version of +const + + +


+

An Example.

+o + const example. + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +The continue statement + + + + +


+
+

The continue statement

+
+
+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. +

+ +continue example.

+ +continue is related to the break +statement.

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +define preprocessor + + + + +


+

#define preprocessor

+
+

+The #define preprocessor allows us to define symbolic names and constants. +A quick example

+

+	#define PI 3.14159
+
+This statement will translate every occurance of PI in the program to 3.14159. +Here is a more complete example:

+

+
+	#define PI 3.14159
+	main()
+	{
+   	   int r=10;
+	   float cir;
+	   cir = PI * (r*r);
+	}
+
+This feature is partically usefull for defining 'magic' numbers.

+ +


+

See Also:

+ + +
+

Examples:

+ +example program.

+ + +Conflict between enum and #define.

+ +

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +The DO keyword. + + + + +


+

The DO keyword.

+
+The do keyword performs a simular function to +while. Basicaly, it repeats a block of statements. +Here is an example of the syntax: +
+        main()
+        {
+          int i=5;
+
+          do
+          {
+            printf(" i is %d\n", i);
+          }
+          while(--i);
+        }
+
+
+ +The program result will look like this: +
+ 		i is 5
+ 		i is 4
+ 		i is 3
+ 		i is 2
+ 		i is 1
+
+The main difference between do and while is +the time that expression is evaluated. + +
+

Examples:

+ + +Basic do. +
+ +
+

See also:

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +The enum statement + + + + +


+
+

The enum statement

+
+
+

+ENUM is closely related to the #define +preprocessor.

+It allows you to define a list of aliases which represent integer numbers. For +example if you find yourself coding something like: +

+        #define MON 1 
+        #define TUE 2 
+        #define WED 3 
+
+You could use enum as below. +
+        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 };
+ 
+
+ +An advantage of enum over #define is that it has +scope +This means that the variable (just like any other) is only visable +within the block it was declared within. +

+


+

Notes:

+ + + +
+

See Also:

+ + C++ Enhancements to enum.

+#define preprocessor.

+ +


+

Examples:

+ + +enum example 1.

+ +enum example 2.

+ + +enum coding error.

+ + +Another enum coding error.

+ + +enum and #define coding error.

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +The FOR keyword. + + + + +


+

The FOR keyword.

+
+The for keyword is used to +repeat a block of code many times. +

+

+ +
+

Basic principles

+Say you wanted to print all the numbers between 1 and 10, you could write: +
+	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++);
+        }
+
+ +As you can see this program would NOT be very practical if we wanted +1000 numbers. The problem can be solved with the for statement +as below. +
+	main()
+        {
+	   int count;
+
+           for ( count=1 ; count <= 10 ; count++) printf("%d\n", count);
+        }
+
+ +The for statement can be broken down into 4 sections: +

+

+
count=1 +
is the initalisation.

+ +

count <= 10 +
An expression. The for statement continues to loop while this +statement remains true

+ +

count++ +
increament or +decreament.

+ +

printf("%d\n", count) +
the statement to execute.

+

+ + +
+

Repeating several lines of code

+ +The previous example showed how to repeat ONE statement. This example +shows how many lines can be repeated. + +
+	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);
+           }
+        }
+
+ +The { and } following the for statement define +a
block of statements. + + +
+

More detail

+ +The for statement performs the following functions while looping. + +
+	for (expression_1 ; expression_2 ; expression_3) statement ;
+
+
    +
  1. Executes expression_1.

    +

  2. Executes statement. +
  3. Executes expression_3. +
  4. Evaluates expression_2. +

    +

      +
    • If TRUE, Jumps to item 2. +
    • If FALSE, Stops looping. +
    +
+ +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.

+ +The following example is an infinite loop: + +

+	main()
+	{
+	   for( ; ; ) puts(" Linux rules!");
+	}
+
+ + + +
+

Examples:

+ +
+Basic for example. +
+ + +Advanced for example. +
+ +
+

See also:

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 + +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 @@ +Functions and passing arguments. + + + + +

+
+

Functions and passing arguments.

+
+
+A function is a block of code that can be executed many times by other +functions or its self. + + +
+

Function Basics.

+You should already understand the concept of functions! If you don't, you +are a sad sad man....

+Might expand on this one day.

+P.S. main() is a function. + +

Declaration.

+Just like variables, all functions have to be +declared before use. Here is an +example. +
+        int add( int, int);
+
+This statement declares a function called add, it has two integer +arguments and returns an integer. + +

Definition.

+The
definition is the meat of the +function. Heres an example. + +

Passing values.

+Passing values is known as call by value. 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 call by value +

Passing pointers.

+This is known as call by reference 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.

+

+ Example of passing a pointer to a scalar. +

+ + +C++ has a nice feature called +reference variables +which is a tider +approch to modifing the contents of a passed variable. + + +

Passing Arrays.

+
+ Example of passing a pointer to an integer array. +
+ Example of passing a pointer to a two +dimensional integer array. +
+ Example of passing a pointer to a +character array. +
+ Example of passing a two dimensional +character array. +

Variable number of parms (...)

+ +
+ Example of passing an unknown number +of variables to a function + +
+ Man page for va_start, va_end etc + +

Function recurssion.

+

Returning values.

+ +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. +

+Here is an example +

+The contents of 'c' are copied into 'i'. + +

Returning pointers.

+ +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 +'static' storage class +otherwise you are going to get some unpredictable +results. + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +Global and Local variables declaration. + + + + +


+
+

Global and Local variables.

+
+
+

+ +

Local variables

+Local variables must always be +defined +at the top of a block. +

+ +C++ has changed the rules regarding where you can define a +local variable. +Click here +for the low down. + +

+When a local variable is +defined +- it is not initalised by the system, you +must initalise it yourself.

+A local variable is +defined + inside a block and is only visable +from within the block. +

+

+ + + + +
+
+
+   main()
+   {
+       int i=4;
+       i++;
+   }
+
+
+
+
+

+When execution of the block starts the variable is +available, and when the block ends the variable 'dies'.

+A local variable is visible within nested blocks unless a variable with +the same name is +defined + within the nested block. +

+

+ + + + +
+
+
+   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.        */
+   }
+
+
+
+
+

+ +


+

Global variables

+ + +C++ has enhanced the use of +
global variables. + +

+Global variables ARE initalised by the system when you +define + them! +

+

+ + + + + + + +
Data Type Initialser
int 0
char '\0'
float 0
pointer NULL
+
+

+In the next example i is a global variable, it can be seen and modified by + main and any other functions that may reference it. +

+

+ + + + +
+
+
+   int i=4;
+   
+   main()
+   {
+       i++;
+   }
+
+
+
+
+

+ +Now, this example has global and Internal variables. +

+

+ + + + +
+
+
+   int i=4;          /* Global definition   */
+   
+   main()
+   {
+       i++;          /* global variable     */
+       func
+   }
+
+   func()
+   {
+       int i=10;     /* Internal declaration */
+       i++;          /* Internal variable    */
+   }
+
+
+
+
+

+ +i in main is global and will be incremented to 5. i in +func is internal and will be incremented to 11. When control returns +to main the internal variable will die and and any reference to +i will +be to the global.

+ + +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.

+


+

Example:

+ +An Example program. +
+

See Also:

+See Storage classes to see the more powerfull +features of variable declarations. + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + + 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 @@ +Got Ya + + + + +


+
+

Got Ya

+
+
+ + + +
+An error which almost every C programmer has made is shown below: +
+	main()
+	{
+	   int left=10;
+	   		
+	   if ( left = 5 )
+	   {
+	      puts(" Values are equal...");
+	   }
+        }
+
+The program assigns 5 to the variable left and returns 5. +This is interpreted as
TRUE and causes the +puts statement to be executed everytime. +

+Here is the corrected program. +

+	main()
+	{
+	   int left=10;
+	   		
+	   if ( left == 5 )		/* Double equals required. */
+	   {
+	      puts(" Values are equal...");
+	   }
+        }
+
+ +
+ +
+

See Also:

+ + +Coding idioms.

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +The GOTO keyword. + + + + +


+
+

The GOTO keyword.

+
+
+Well, I have resisted adding goto 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 +goto is never required and I dont have reason to disagree, but +you may like to differ. + +

goto syntax

+ +
+	goto lab1;
+
+	lab1:
+
+goto allows the program to 'jump' to a named label, in this case lab1, +the target label MUST be terminated with a : (colon). + + +
+

An Example.

+ +goto example. + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +Idioms + + + + +


+
+

Idioms

+
+
+

+ +Here are some C idioms that may be usefull. + +


+Place \0 at the location pointed to by ptr +then increment ptr +

+

+ + +
+
+
+   *ptr++ = '\0';   
+
+
+
+ +


+Increment ptr then +place \0 at the location pointed to by ptr +

+

+ + +
+
+
+   *++ptr = '\0';   
+
+
+
+ +


+This program will print its self! I guess its not of any real +use, but I think its clever. +

+

+ + +
+
+
+  main(a) {a="main(a) {a=%c%s%c;printf(a,34,a,34);}";printf(a,34,a,34);}  
+
+
+
+ +


+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. +

+

+ + +
+
+
+   one ^= two;   
+   two ^= one;
+   one ^= two;
+
+
+
+ + +


+ +Have you ever had a SEGV from printf +because you passed a NULL pointer to a %s flag???. This idiom will put +a stop to all that nonsence. +

+

+ + +
+
+
+   printf("%s\n", Str ? Str : "Null");   
+
+
+
+ + + +


+

+o +Program swapping the contents of two variables. +

+ +


+

See Also:

+ +o +Common Coding Errors.

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +if-else keywords. + + + + + + +


+
+

The 'if' and 'else' keywords

+
+
+

+ +The if-else statement is a two-way decision statement. It is written as + +

+	if ( expression )	statement1;
+	[else			statement2;]
+
+ +The else portion is optional. If the expression evaluates to +true +(anything other than 0) then statement1 is executed. If there is an else +statement and the expression evaluates to +false +statement2 is executed. + +For example + +
+(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;
+
+ +Consider this code fragment: +
+	if( p == 1 )
+	  if( q == 2 )	r = p * 2 + q;
+        else r = q * 2 + p;
+
+Because the else part is optional, there is an ambiguity when an else is +omitted from a nested if sequence. In 'C', this is resolved by associating +the else with the closest previous if that does not have an else. +Therefore, in the above example, the else part belongs to the if(q==2) +statement. + +The code can be made more readable by explicitly putting parentheses in +the expression, like this + +
+	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;
+        }
+
+ +Because the statement in the else part can also be an if statement, a +construct such as shown below is possible in 'C' to create a multiple +choice construct. + +
+	if( expression1 )
+	  statement1;
+	else if( expression2 )
+	  statement2;
+	else if( expression3 )
+	  statement3;
+	.
+	.
+	else
+	  statementN;
+
+ +
+

Example:

+ + Basic if example. +
+
+

See also:

+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + + 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 @@ +include preprocessor + + + + +


+
+

include preprocessor.

+
+
+The include preprocessor will add source code to your existing source. This +is used to include header files that contain function declarations. +For example:

+

+	#include <stdio.h>
+	main()
+	printf("hi peeps");
+	}
+
+The printf function declaration is held in stdio.h

+There are two ways of defining the include files location. +

    +
  • <>says to the preprocessor that the file is in the system libraries. +
    +	#include <stdio.h>
    +
    + +
  • ""means that this is a user defined file. Absolute or relative +paths may be defined. +
    +	#include "myheaders.h"
    +	#include "/usr/home/leslim/myheaders.h"
    +
    +
+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ + + + + + + C keywords. + + + +


+
+

+C keywords.

+ +
The following list shows all the ANSII defined C keywords. I have included +sizeof because it looks like a keyword and it +keeps the table below tidy.... +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
autobreakcasecharconstcontinuedefaultdo
doubleelseenumexternfloatforgotoif
intlongregisterreturnshortsignedsizeofstatic
structswitchtypedefunionunsignedvoidvolatilewhile
+ +

+


C++ extends the language to include these +keywords +
+
+
+ + + + + + + + + +
TopMaster IndexKeywordsFunctions
+ +

+


+
+Martin Leslie
+ + + 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 @@ +Logical AND OR and NOT + + + + +
+
+

Logical AND OR and NOT

+
+
+ + +
+ +

Logical AND

+In simple terms, && is true (1) if both sides of the expression returns NOT 0. +

+For Example: +

+	/* These all return TRUE (1) */
+
+	if (4 && 5) return();
+
+	i=3;
+	j=2;
+	return( i && j);
+
+The expression is evaluated 'Left to Right' If any part of the expression +returns ZERO - The evaluation ends. +

+THIS CAN CAUSE SERIOUS PROBLEMS. +

+For example: +

+	k=0;
+	i=3;
+	j=2;
+	if ( i-i && j++) k=1
+
+The left side (i-i) resolves to 0, so j is not incremented +and k is not changed. +
+
+

Logical OR

+OR also evaluates 'Left to Right' and will stop when an expression +returns true.

+SO WATCH YOUR BACK.... +

+

+	k=0;
+	i=3;
+	j=2;
+	if ( i+i && j++) k=1
+
+What are j and k going to be when this code is executed????? + +
+
+

Logical NOT

+ +NOT reverses the logical state of its +
operand. If the operand is 0, 1 is +returned, else 0 is returned. + +
+	!4	/* Returns 0	*/
+	!-4	/* Returns 0	*/
+	!1	/* Returns 0	*/
+	!0	/* Returns 1	*/
+
+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +Macros + + + + +


+
+

Macros

+
+
+

+Macros are built on the #define +preprocessor.

+Normally a #define would look like: +

+	#define PI 3.142
+
+But, a macro would look like this. +
+	#define SQUARE(x) x*x
+
+The main difference is that the first example is a constant and the second +is an expression. +If the macro above was used in some code it may look like this: +
+        #define SQUARE(x)  x*x
+
+        main()
+        {
+          int value=3;
+          printf("%d \n", SQUARE(value));
+        }
+
+After preprocessing the code would become: +
+        main()
+        {
+          int value=3;
+          printf("%d \n", value*value);
+        }
+
+
+

Examples:

+ + +macro example.

+


+

Notes:

+
    +
  • The value passed to SQUARE could have been an +int +float +or +double +
  • Long macros can span multiple lines by using a +\ followed by a newline +(return). +
  • If you are using gcc to compile your code, you can use the -E option to +see the preprocessor output +
+
+

See Also:

+
    +
  • #define preprocessor. + +
  • inline A C++ keyword that provides a better aproch to macros. + +
+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +XXX + + + + + + +


+
+

XXXX

+
+
+XXXX +

+


+ +
+

Examples:

+ + example +program. + +
+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +Null + + + + +


+

NULL

+
+

+NULL is used in several ways. +

    +
  • As a pointer to address zero. NULL is defined in several ANSI headers +as the +symbolic constant +(void *)0. 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. +
    +	if ((fp=fopen("/etc/hosts","r") == NULL)
    +        {
    +          exit(0);
    +        }
    +
    +

    +

  • To mark the end of a character string. A null character is used to +terminate the string. For example if you coded: +
    +	char * text="abc";
    +
    +You will actually reserve FOUR bytes containing in ASCII hex. +
    +	61 62 63 00
    +	 a  b  c \0
    +
    +The null at the end can be coded by using the +escape sequence '\0'. +
+

+\0 is actually an octal escape sequence, +strictly speeking it should +be written as \000 +

+


+

ANSI headers

+The following headers define NULL. +
    +
  • locale.h +
  • stddef.h +
  • stdio.h +
  • stdlib.h +
  • string.h +
  • string.h +
  • time.h + + +

    + +


    +

    +

    + + + + +
    + Top + + Master Index + + Keywords + + Functions +
    +
    +

    +


    +
    Martin Leslie +

    + + 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 @@ +C compiler preprocessors + + + + +


    +
    +

    C compiler preprocessors

    +
    +
    + +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. +

    + + + + + + + + + + + + + + +
    Preprocessors
    #include Insert a source file. +
    #define Define a preprocessor +constant. +
    #if Branch based on an expression. +
    #ifdef Branch if preprocessor constant has been defined? +
    #ifndef Branch is a preprocessor +constant has NOT been defined. +
    #line Specify the number of the next source line. +
    #undef Remove a preprocessor constant. +
    #pragma Perform an implementation dependent action??? +
    #else Executed if #if +#ifdef or #ifndef fails. +
    #error Write an error message. +
    #elif Executed when an #if fails. +
    #endif Close #if #ifdef or +#ifndef +
    +


    +

    Notes:

    +
      +
    • Preprocessors should start in column 1. +
    • The -E option tells gcc to stop after the preprocessor stage and send the +O/P to STDOUT (usually the screen). +
    + + +

    + +


    +

    +

    + + + + +
    + Top + + Master Index + + Keywords + + Functions +
    +
    +

    +


    +
    Martin Leslie +

    + + 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 @@ +The return statement + + + + +


    +
    +

    The return statement

    +
    +
    +

    +return will return a value from a function to its caller. +The value returned is +the result of an expression. +

    +


    +As an Example this will print 7 + +

    + + + + +
    +
    +
    +        int func(void);
    +
    +	main()
    + 	{
    +	   printf("%d \n", func());
    +        }
    +
    +        int func(void)
    +        {
    +           return 7;
    +	}
    +
    +
    +

    + +What ever follows the return statement will be evaluated as +an expression. So, to be consistant you could place brackets around +the return value. + +

    + + + + +
    +
    +
    +        return(7);
    +
    +
    +

    +Or you could evaluate a formula on the statement: + +

    + + + + +
    +
    +
    +	return (Count-1);
    +
    +
    +

    +Finally, if the function returns a void +the return statement is not required, but maybe needed to +leave a function before the end of the function block. Here +is an example. + +

    + + + + +
    +
    +
    +	void CheckDate(int)
    +
    +	main()
    +	{
    +	  CheckDate(40)
    +        }
    +
    +	void CheckDate(int Month)
    +	{
    +	  if (Month > 31)
    +	  {
    +	    return;
    +	  }
    +
    +	  puts("Month is valid");
    +        }
    +
    +
    +

    +


    +

    See also:

    +The exit function. + + +

    + +


    +

    +

    + + + + +
    + Top + + Master Index + + Keywords + + Functions +
    +
    +

    +


    +
    Martin Leslie +

    + + 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 @@ +The sizeof operator + + + + +


    +
    +

    The sizeof operator

    +
    +
    +

    +sizeof will return the number of bytes reserved for a variable or +data type. +

    +The following code shows sizeof returning the length of a data type. +

    + + + + +
    +
    +
    +        /* How big is an int? expect an answer of 4. */
    +	
    +	main()
    + 	{
    +	   printf("%d \n", sizeof(int));
    +        }
    +
    +
    +

    + +sizeof will also return the number of bytes reserved for a +structure. +

    + + + + +
    +
    +
    +        /* Will print 8 on most machines. */
    +	
    +        main()
    +	{
    +	  struct 
    +	  {
    +	    int a;
    +	    int b;
    +	  } TwoInts;
    +	
    +	printf("%d \n", sizeof(TwoInts));
    +	}
    +	
    +
    +
    +

    +Finally, sizeof will return the length of a variable. + +

    + + + + +
    +
    +
    +	main()
    +	{
    +	  char String[20];
    +	  
    +	  printf ("%d \n", sizeof String);
    + 	  printf ("%d \n", sizeof (String));
    +        }
    +
    +
    +
    +

    +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. +

    +


    +

    Examples:

    +Example 1 Data types. +

    +Example 2 Data objects. + +

    +


    +

    See also:

    + +The strlen function. +

    + +Other operators +

    + +malloc function. + + +

    + +


    +

    +

    + + + + +
    + Top + + Master Index + + Keywords + + Functions +
    +
    +

    +


    +
    Martin Leslie +

    + + 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 @@ +C statements and blocks + + + + +


    +
    +

    C Statements and blocks.

    +
    +
    +

    Statements

    +C has three types of statement. +
      +
    • assignment +
      +	=
      +
      +
    • selection (branching) +
      +	if (expression)
      +	else
      +	switch
      +
      +
    • iteration (looping) +
      +	while (expression)
      +	for (expression;expression;expression)
      +	do {block}
      +
      +
    + + +

    Blocks

    +
+These statements are grouped into blocks, a block is identified by +curly brackets...There are two types of block. + + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +static functions + + + + + + +


+
+

static functions

+
+
+

+ +static functions are functions that are only visable to other +functions in the same file. Consider the following code. +

+ + + + + +
+main.c +
+
+
+   #include 
+
+   main()
+   {
+     Func1();   
+
+     Func2();
+   }
+   
+
+
+ + + + + + +
+funcs.c +
+
+
+   /*************************************
+    *
+    * Function declarations (prototypes).
+    *
+    *************************************/
+
+   /* Func1 is only visable to functions in this file. */   
+
+   static 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");
+   }
+   
+
+
+

+If you attempted to compile this code with the following +command, +

+ +

+ + + + +
+
+
+   gcc main.c funcs.c   
+
+
+
+

+it will fail with an error simular to..... +

+ +

+ + + + +
+
+
+   undefined reference to `Func1'  
+
+
+
+

+Because 'Func1' is declared as static +and cannot be 'seen' by 'main.c'. +

+


+

Notes:

+For some reason, static has different +meanings in in different contexts. +
    +
  1. When specified on a function declaration, it makes the +function local to the file. +

    +

  2. When specified with a variable inside a function, it +allows the vairable to retain its value between calls to +the function. See +static variables. +
+It seems a little strange that the same keyword has such +different meanings.... + +

+


+

See Also:

+ + +static variables

+ + + +C++ extensions for static

+ + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +C Storage Classes + + + + + +

+
+

C Storage Classes.

+
+
+

+C has a concept of 'Storage classes' which are used to define the +scope (visability) and life time of variables and/or functions. +

+So what Storage Classes are available? +

+ + + +
auto +register +static +extern +typedef +
+

+


+

auto - storage class

+auto is the default storage class for local variables. +
+	{
+            int Count;
+            auto int Month;
+	}
+
+ +The example above defines two variables with the same storage class. +auto can only be used within functions, i.e. local variables.

+


+

register - Storage Class

+register 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). +
+	{
+            register int  Miles;
+	}
+
+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.

+


+

static - Storage Class

+static is the default storage class for global variables. The two +variables below (count and road) both have a static storage class. +
+	static int Count;
+        int Road;
+
+        {
+            printf("%d\n", Road);
+        }
+
+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.

+'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. + +

+	{
+	    static Count=1;
+        }
+
+Here is an
example

+ + +There is one very important use for 'static'. Consider this bit of code. +

+        char *func(void);
+
+        main()
+        {
+            char *Text1;
+            Text1 = func();
+        }
+
+        char *func(void)
+        {
+            char Text2[10]="martin";
+            return(Text2);
+        }
+
+ +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 +
+	static char Text[10]="martin";
+
+The storage assigned to 'text2' will remain reserved for the duration if the +program. +

+


+ +C++ has overloaded static,
here +are the details. + +
+

extern - storage Class

+extern 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. + + + + + + + + +
+Source 1 + +Source 2 +
+
+
+extern int count;			int count=5;
+
+write()					main()
+{					{
+    printf("count is %d\n", count);         write();
+}					}
+
+
+test +
+ +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. +

+Source 1
+Source 2

+ +The compile command will look something like.

+

+	gcc source1.c source2.c -o program
+
+ +
+

See Also:

+Data types. + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +STRUCT keyword + + + + + + +


+

STRUCT keyword

+
+

+ +

+ + +
+

Structure basics

+ +struct is used to declare a new +
data-type. +Basically this means +grouping variables together. For example, a struct data type could be used +to declare the format of the following file.

+ +

+ + +
+
          
+   Jo		Loss		Maths		A   
+   Harry	Carpenter	English 	A
+   Billy	King		Maths		C
+
+
+
+

+ +The records above could be described in a struct as follows: +

+

+ + +
+
   
+
+   struct
+   {
+       char cname[8];
+       char sname[16];   
+       char exam[16];
+       char grade;
+   } record;
+
+
+
+
+

+The statement above declares a variable called record with 4 members +called cname, sname, exam, grade. The structure as a whole can be +referred to as record and a member can be referenced as +record.exam +

+ +Structures can be declared in various forms... +

+ +

+	struct x {int a; int b; int c;};		/* declaration	*/
+	struct 	 {int a; int b; int c;} z;
+	struct x z;
+
+All the examples above are structure declarations, +
    +
  • The first gives x as a 'structure tag' - this is optional. +
  • The first and second declare the members of the structure. +
  • Second and third give z this is the variable that assumes the +structure type. +
+

+ + +


+

Structure membership

+ +We can access individual members of a structure with the . operator.

+For example to assign a value, we can enter: +

+

+ + +
+
+	
+   struct x {int a; int b; int c;};   
+
+   main()
+   {
+      struct x z;
+     
+      z.a = 10;
+      z.b = 20;
+      z.c = 30;
+   }
+   
+
+
+
+

+And to retrieve a value from a structure member: +

+

+ + +
+
+
+   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);   
+   }
+   
+
+
+
+

+ +


+

Pointers to structures

+ +
Fast path to an explanation of the -> operator. +

+ +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. +

    +
  • If the structure is large it is more effiecent to pass a +pointer to the structure +instead of the structure its self. This technic is also used to pass +pointers to arrays between +functions. +

    +

  • 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. +
+

+So how does it all work? Here is an example. (make your browser W-I-D-E so +you can see the two examples). +

+

+ + +
+
+					|
+					|
+   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;	     /* 3 */
+					|   pz = &z;		     /* 4 */
+     z.a = 10;		/* 1 */		|   z.a = 10;
+     z.a++;				|   z.a++;
+					|
+     function(z);	/* 2 */	        | function(pz);		     /* 5 */
+   }					| }
+					|
+   void function( struct x z)		| void function(struct x * pz)
+   {					| {			     /* 6 */
+     printf(" first member %d \n", z.a);|   printf(" first member %d \n", (*pz).a);   
+   }					| }
+					|
+
+
+
+

+Here is the annotation. +

    +
  1. Give a structure member a value. +
  2. Pass a COPY of the whole structure to the function. +
  3. Define 'pz' a pointer to a structure of type 'x'. +
  4. 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. +
  5. Pass the pointer into the function. +
  6. Print the value of the member 'a'. +
+ + +The (*pz).a syntax is used a great deal in C and it was decided to create +a short hand for it. So: + +
+	(*pz).a   ==  pz->a
+
+ +Here is the final picture. +
+
+   /*************************************************************************/
+
+   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++;
+     
+   }
+
+   /*************************************************************************/
+  
+
+
+ +
+

+


+

The Bottom Draw

+ +Finally, here is a little feature that allows you to save a little +space. +

+

+ + +
+
+
+  main()
+  {
+    struct Flags
+    {
+      unsigned int Online  :1;   
+      unsigned int Mounted :1;
+    }
+
+    struct Flags TapeInfo;
+
+    TapeInfo.Online  = 1;
+    TapeInfo.Mounted = 0;
+  }
+  
+
+
+
+

+The :1 tells the compiler that only 1 byte is +required for Online and Mounted. There are a few points to +note about this though. +

    +
  • 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. +
  • You can put any number into the variable, if the number is too large +to fit, the high order bits are lost without warning. +
  • Only signed int, unsigned int, int support this syntax. +
+
+ +

Examples

+

+ + +This is the most basic struct example I could think of. +
+ + + +Using structure elements, and passing them into a function. +
+ + + +Passing a whole structure to a function. This performs a copy of the +structure so the same rules apply as for int etc. +Pointers to structures can be passed but I have not got to them yet.... +
+ + + +Define and use an array of structures. +
+ + + +Here is a struct problem for you. + + + +


+

See Also:

+ +typedef keyword. +
+ +Linked lists. +
+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +switch/case keywords + + + + + + +


+
+

The 'switch' and 'case' keywords

+
+
+

+ +The switch-case statement is a multi-way decision statement. Unlike the +multiple decision statement that can be created using +if-else, the switch +statement evaluates the conditional +expression and tests it against +numerous +constant +values. The branch corresponding to the value that the +expression matches is taken during execution. +

+The value of the expressions in a switch-case statement must be an ordinal +type i.e. +integer, char, short, long, +etc. Float and double are not +allowed. +

+The syntax is : +

+

+ + + + +
+
+
+     switch( expression )
+     {
+        case constant-expression1:	statements1;
+        [case constant-expression2:	statements2;]    
+        [case constant-expression3:	statements3;]
+        [default : statements4;]
+     }
+
+
+
+

+ +The case statements and the default statement can occur in any +order in +the switch statement. The default clause is an optional clause +that is +matched if none of the constants in the case statements can be matched. +

+Consider the example shown below: +

+

+ + + + +
+
+
+     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?" );
+     }		
+
+
+
+

+ +Here, if the Grade is 'A' then the output will be +

+

+ + + + +
+
+     Excellent
+     Good
+     OK
+     Mmmmm....
+     You must do better than this    
+     What is your grade anyway?
+
+
+
+

+ +This is because, in the 'C' switch statement, execution continues on into +the next case clause if it is not explicitly specified that the execution +should exit the switch statement. The correct statement would be: +

+

+ + + + +
+
+
+     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;
+	}		
+
+
+
+

+ +Although the break in the default clause (or in general, after +the last +clause) is not necessary, it is good programming practice to put it in +anyway. +

+An example where it is better to allow the execution to continue into the +next case statement: +

+

+ + + + +
+
+
+     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;
+
+     }
+     .
+     .
+
+
+
+

+ +


+

Example:

+ +Basic switch example. +
+
+

See also:

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + diff --git a/reference/C/SYNTAX/syntax.gif b/reference/C/SYNTAX/syntax.gif new file mode 100644 index 0000000..737bb1f Binary files /dev/null and b/reference/C/SYNTAX/syntax.gif differ 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 @@ + + +C Syntax + + + +


+
+Syntax +
+
+

+The following items highlight the main areas of C syntax. +

+


+ +If nothing appears below this line, +click on low tech links. + +
+
+
+
+
+
+
+
+
+

+ +

+
+
+
+
+
+

+ +

+
+
+
+

+ +

+

+ +

+
+

+ +

+

+

+
+ +
+ +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ + + + + + + C Syntax + + + +


+
+ +
+

The following items highlight the main areas of C syntax. +

+


If your browser can support JavaScript click +here. +
+ + +
+
+ + + + + + + + + +
TopMaster +IndexKeywordsFunctions
+ +

+


+
+Martin Leslie
+ + + 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 @@ + + +The TYPEDEF keyword. + + + +
+

The TYPEDEF keyword.

+
+

+Every variable has a +data type. typedef is used to define +new data type names to make a program more readable to the programmer. +

+For example: +

+ +
+
+
+				|
+	main()	                |   main()
+        {	                |   {
+  	    int money;          |       typedef int Pounds;
+            money = 2;          |       Pounds money = 2
+        }	                |   } 
+
+
+

+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. +

+ +A common use for typedef is to define a boolean data type as below. + +
+Note: Recent C++ compilers have introduced a boolean datatype. +

+ +

+ +
+
+
+	typedef enum {FALSE=0, TRUE} Boolean
+
+	main ()
+        {
+	    Boolean flag = TRUE;
+	}
+        
+
+
+

+ +And as a final example, how about creating a string datatype? +

+ +
+
+
+     typedef char *String;
+     
+     main()
+     {
+         String Text = "Thunderbird";
+       
+         printf("%s\n", Text);
+     }
+     
+
+
+

+ +The main use for typedef seems to be defining +structures. For example: +

+ +
+
+
+	typedef struct {int age; char *name} person;
+	person people;
+
+
+
+

+ +Take care to note that person is now a type specifier and NOT a +variable name. +

+As a final note, you can create several data types in one hit. + +
+
+
+
+	typedef int Pounds, Shillings, Pennies, Dollars, Cents;  
+
+
+
+

+ +

+


+

Examples:

+ +Here is a rather heavy example of typedef. +
+
+

Notes:

+I would expect to see 'typedef' in header files. + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + + 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 @@ +The UNION keyword. + + + + +


+

The UNION keyword.

+
+ +The union keyword allows several +variables of different type and size to occupy the same storage location. +

+The syntax to define a union is simular to the +struct keyword as shown below:

+ + +

+	union union_def { int a; float b; char c;} ;
+
+ +and a variable declared with either of these statements: + +
+	union union_def union_var;
+	union { int a; float b; char c;} union_var;
+
+ +If you wish to initalise a variable you can say: + +
+	union { int a; float b; char c;} union_var=97;
+
+ +By default the first variable (a) is initalised. +

+ +To assign a value to a variable you can say: + +

+	union_var.b=99.99;
+	union_var.a=34;
+	union_var.c='x';
+
+It's important to note that the storage will only hold ONE value, +looking at the +three lines above, union_var.a overwrites union_var.b and +then union_var.c overwrites union_var.a

+ + + +I have yet to see more than one use for this keyword. +


+

Examples:

+ + Here is an example. +
+
+

See also:

+ + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ +The VOID keyword. + + + + +


+

The VOID keyword.

+
+

+The void keyword +allows us to create functions that either do not require any +parameters or do not return a value.

+The following example shows a function that does not return +a value. +

+ + + + +
+
+
+	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);
+	}
+
+
+

+The next example shows a function that does not require any parameters: +

+ + + + +
+
+
+	#include 
+	#include 
+
+        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());
+        }
+
+
+
+

+


+

Example:

+ +void example +
+

See also:

+ +Functions +Void pointers +

+ + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ + + +The VOLATILE keyword. + + + +


+

The VOLATILE keyword.

+
+I have had several sugestions on how to describe volatile, +If you have any input please mail me. +
    +
  • The volatile keyword acts as a +data type 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. Martin Leslie +

    +

  • volatile 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.Stephen Hunt +

    +

  • Here is an example for the usage of the volatile keyword: +
    +	/* 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;
    +
    +Between reads the bytes are changed in the latch. +

    +Without the volatile, the compiler optimises this to a single assignment: +

    +	lsb = middle = msb = *handle->baseAddr;
    +
    +Tim Potter +

    +

  • A volatile variable is for dynamic use. E.G. for data that is to +be passed to an I/O port Here is an example. + +
    +	#define TTYPORT 0x17755U
    +
    +	volatile char *port17 = (char)*TTYPORT;
    +	*port17 = 'o';
    +	*port17 = 'N';
    +
    +Without the volatile modifier, the compiler would think that the +statement *port17 = 'o'; is redundant and would remove it +from the object code. The volatile statement prevents the compiler +optimisation.Alex Arzon. +
+ +
+

Examples:

+o No example:-( +
+
+

See also:

+ + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + 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 @@ + + +The WHILE keyword. + + + +


+

The WHILE keyword.

+
+The while keyword is related to do +and for. Its purpose is to repeatedly execute +a block of statements. Here is +an example : + +

+

+ + + + +
+
+
+        main()
+        {
+            int i=5;
+
+            while(--i)
+            {
+                printf(" i is %d\n", i);
+            }
+        }
+
+
+
+

+ +The expression i-- is evaluated and if its +true the statements in the +block are executed. +The loop continues until the expression is false (zero). +The result will look like this: + +

+

+ + + + +
+
+                
+                i is 4
+                i is 3
+                i is 2
+                i is 1
+
+
+
+

+ +It is important to note that the statements +on a while 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 do statement. + +


+

+Now consider the next example. + +

+

+ + + + +
+
+
+        main()
+        {
+            int i=5;
+
+            while(--i);
+            {
+                printf(" i is %d\n", i);
+            }
+        }
+
+
+
+ + +The result will look like this: + + +

+

+ + + + +
+
+
+                i is 0
+
+
+
+ +

+This is because of the ; on the end of the while +statement which means the while will loop (executing NULL statements) +until i is zero. Execution will then continue down the program +(to the printf). +

+ +


+

Examples:

+ +o +Basic while. +
+ +
+

See also:

+ + + +

+ +


+

+

+ + + + +
+ Top + + Master Index + + Keywords + + Functions +
+
+

+


+
Martin Leslie +

+ + -- cgit v1.2.3-54-g00ecf