diff options
Diffstat (limited to 'reference/C/CONCEPT')
-rw-r--r-- | reference/C/CONCEPT/JavaSim.html | 254 | ||||
-rw-r--r-- | reference/C/CONCEPT/Makefile.am | 5 | ||||
-rw-r--r-- | reference/C/CONCEPT/Makefile.in | 410 | ||||
-rw-r--r-- | reference/C/CONCEPT/arrays.html | 212 | ||||
-rw-r--r-- | reference/C/CONCEPT/assignment.html | 91 | ||||
-rw-r--r-- | reference/C/CONCEPT/bit_shift.html | 219 | ||||
-rw-r--r-- | reference/C/CONCEPT/bitsnbytes.html | 84 | ||||
-rw-r--r-- | reference/C/CONCEPT/bitwise.html | 231 | ||||
-rw-r--r-- | reference/C/CONCEPT/cast.html | 75 | ||||
-rw-r--r-- | reference/C/CONCEPT/cmdline.html | 48 | ||||
-rw-r--r-- | reference/C/CONCEPT/constants.html | 143 | ||||
-rw-r--r-- | reference/C/CONCEPT/data_types.html | 218 | ||||
-rw-r--r-- | reference/C/CONCEPT/expressions.html | 135 | ||||
-rw-r--r-- | reference/C/CONCEPT/inc_dec.html | 84 | ||||
-rw-r--r-- | reference/C/CONCEPT/pointers.html | 559 | ||||
-rw-r--r-- | reference/C/CONCEPT/precedence.html | 376 | ||||
-rw-r--r-- | reference/C/CONCEPT/rpc.html | 356 | ||||
-rw-r--r-- | reference/C/CONCEPT/storage_class.html | 219 | ||||
-rw-r--r-- | reference/C/CONCEPT/string.html | 157 | ||||
-rw-r--r-- | reference/C/CONCEPT/true_false.html | 78 | ||||
-rw-r--r-- | reference/C/CONCEPT/type_conv.html | 63 |
21 files changed, 4017 insertions, 0 deletions
diff --git a/reference/C/CONCEPT/JavaSim.html b/reference/C/CONCEPT/JavaSim.html new file mode 100644 index 0000000..416e666 --- /dev/null +++ b/reference/C/CONCEPT/JavaSim.html @@ -0,0 +1,254 @@ +<title>Bit Manipulation Simulator</title> + +<head> +<script language="JavaScript"> + +function BitWise(form) +{ + // ... Convert the supplied hex numbers to decimal. + + var Left = HexToDec(form.Left.value); + var Right = HexToDec(form.Right.value); + + // ... Get the operation symbol (& | >> <<); + + var Operation = form.Operation[form.Operation.options.selectedIndex].value; + + Oper = Operation; + + // ... Do the calculation in decimal. + + var DecAns = eval(Left + Operation + Right); + + // ... convert the answer back to Hex format. + + var BinAns = DecToBin(DecAns); + + form.Ans.value = BinToHex(BinAns); + + // Butify the inputs. + + BinAns = DecToBin(Left); + + form.Left.value = BinToHex(BinAns); + + BinAns = DecToBin(Right); + + form.Right.value = BinToHex(BinAns); + + // refresh the screen so the table can display the updated values. + + history.go(0); +} + +function HexToDec(Hex) +{ + return(parseInt(Hex, 16)); +} + +function DecToBin(Decimal) +{ + var Index = 128; /* Just look at the 8 + * low order bits */ + var Binary =""; + + while(Index > 0) + { + if (Index == 8) Binary += " "; /* Put a space between the */ + // Bytes */ + + if((Decimal % Index) != Decimal) + { + Binary += "1"; + Decimal -= Index; + } + else + { + Binary += "0"; + } + Index /= 2; + + // Bodge... + + if (Index == 0.5) Index = 0; + } + return(Binary) +} + +function BinToHex(Binary) +{ + var Left = Binary.substring(0,4); + Left = BinToHexConv(Left); + var Right = Binary.substring(5,9); + Right = BinToHexConv(Right); + +return(Left+Right); +} + +function BinToHexConv(Binary) +{ + this["0000"] = "0"; + this["0001"] = "1"; + this["0010"] = "2"; + this["0011"] = "3"; + this["0100"] = "4"; + this["0101"] = "5"; + this["0110"] = "6"; + this["0111"] = "7"; + this["1000"] = "8"; + this["1001"] = "9"; + this["1010"] = "A"; + this["1011"] = "B"; + this["1100"] = "C"; + this["1101"] = "D"; + this["1110"] = "E"; + this["1111"] = "F"; + + return(this[Binary]) +} + +</script> +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Bit Manipulation Simulator</h1> +</center> +<hr> + +This page requires JavaScript support to test the various bitwise operators. +If you do not have JavaScript available, you can try the CGI supported +simulator. +<p> + +<hr> +<p> +<center> +<form name="form1"> +Enter the Hex values and select an operator, then press the 'Execute' +button to see the results. +<p> + +<input type="text" value="00" name="Left" size=4> +<select name="Operation"> +<option value=" & "> & +<option value=" | "> | +<option value=" << "> << +<option value=" >> "> >> +</select> + +<input type="text" value="00" name="Right" size=4> +<input type="Button" value="Execute" name="Ex" onclick="BitWise(this.form)"> +<input type="text" value="00" name="Ans" size=4> +</form> +</center> + +<center> +<table border=2 bgcolor="ivory"> +<tr align=center> + +<td>Hex</td> + +<td>Binary</td> + +<td>Decimal</td> +</tr> + +<tr><td> +<h3> +<script> + +// ... When the document is loaded, this is true +// ... and the default values are set. + +if (document.form1.Operation.options.selectedIndex == -1) +{ + document.form1.Operation.options.selectedIndex = 0; + document.form1.Left.value = 00; + document.form1.Right.value = 00; + document.form1.Ans.value = 00; +} + +document.writeln("<pre>"); +document.writeln(" "); +document.writeln(" " + document.form1.Left.value + " "); +document.write (" " + document.form1.Operation[document.form1.Operation.options.selectedIndex].value); +document.writeln(document.form1.Right.value); +document.writeln(" --"); +document.writeln(" " + document.form1.Right.value); +// document.writeln(" " + document.form1.Operation[1].value); +document.writeln("</pre>"); +</script> +</h3> +</td> + +<td> +<h3> +<script> +document.writeln("<pre>"); +document.writeln(" "); +document.writeln(" " + DecToBin(HexToDec(document.form1.Left.value)) + " "); +document.write (" " + document.form1.Operation[document.form1.Operation.options.selectedIndex].value); +document.writeln(DecToBin(HexToDec(document.form1.Right.value))); +document.writeln(" ---------"); +document.writeln(" " + DecToBin(HexToDec(document.form1.Ans.value))); +document.writeln("</pre>"); +</script> +</h3> +</td> + +<td> +<h3> +<script> +document.writeln("<pre>"); +document.writeln(" "); +document.writeln(" " + HexToDec(document.form1.Left.value) + " "); +document.write (" " + document.form1.Operation[document.form1.Operation.options.selectedIndex].value); +document.writeln(HexToDec(document.form1.Right.value)); +document.writeln(" --"); +document.writeln(" " + HexToDec(document.form1.Ans.value)); +document.writeln("</pre>"); +</script> +</h3> +</td></tr> +</table> +</center> +<p> + +<font color=red> +Sections of this page controlled by 'JavaScript' cannot be printed. +</font> +<p> +<hr> +<h2>See Also:</h2> +<img src=../../GRAPHICS/whiteball.gif> +<a href=../CONCEPT/bitwise.html>Bitwise Operators</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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> +</body diff --git a/reference/C/CONCEPT/Makefile.am b/reference/C/CONCEPT/Makefile.am new file mode 100644 index 0000000..5baa6fe --- /dev/null +++ b/reference/C/CONCEPT/Makefile.am @@ -0,0 +1,5 @@ +EXTRA_DIST = $(wildcard *.html) $(wildcard *.gif) +docs_DATA = $(EXTRA_DIST) + +docsdir = $(kde_htmldir)/en/kdevelop/$(subdir) + diff --git a/reference/C/CONCEPT/Makefile.in b/reference/C/CONCEPT/Makefile.in new file mode 100644 index 0000000..00a7756 --- /dev/null +++ b/reference/C/CONCEPT/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 *.gif) +docs_DATA = $(EXTRA_DIST) + +docsdir = $(kde_htmldir)/en/kdevelop/$(subdir) +subdir = reference/C/CONCEPT +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/CONCEPT/Makefile +#>+ 3 + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu reference/C/CONCEPT/Makefile + cd $(top_srcdir) && perl admin/am_edit reference/C/CONCEPT/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=bitsnbytes.html cast.html assignment.html data_types.html expressions.html true_false.html bitwise.html storage_class.html pointers.html rpc.html arrays.html precedence.html type_conv.html JavaSim.html bit_shift.html string.html constants.html cmdline.html inc_dec.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/CONCEPT/Makefile + cd $(top_srcdir) && perl admin/am_edit reference/C/CONCEPT/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/CONCEPT/arrays.html b/reference/C/CONCEPT/arrays.html new file mode 100644 index 0000000..b56def1 --- /dev/null +++ b/reference/C/CONCEPT/arrays.html @@ -0,0 +1,212 @@ +<title>Arrays</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Arrays.</h1> +</center> +<hr> +Arrays can be created from any of the C data types +<a href="data_types.html#int">int</a>, +<a href="data_types.html#float">float</a>, +<a href="data_types.html#char">char</a>. I start with <b>int</b> and +<b>float</b> +as these are the easiest to understand. Then move onto <b>int</b> +and <b>float</b> +multi dimentional arrays and finally <b>char</b> arrays +<ul> +<li><a href=#int><b>int</b> or <b>float</b> arrays.</a> +<li><a href=#twod>two dimensional <b>int</b> or <b>float</b> arrays.</a> +<li><a href=#char><b>char</b> arrays.</a> +<li><a href=#chard><b>char</b> multidimentional arrays.</a> +</ul> + +<a name="int"> +<hr> +<h2>int and float arrays</h2> +To <a href="../glossary.html#definition">define</a> an integer or +floating point variable you would say. +<pre> + main() + { + int Count; /* integer variable */ + float Miles; /* floating point variable */ + } +</pre> +The syntax for an array is: +<pre> + main() + { + int Count[5]; /* 5 element integer array */ + float Miles[10]; /* 10 element floating point array */ + } +</pre> + +Now, the <b>important</b> fact is that the elements start at 0 (ZERO), so, +'Count' above has elements 0, 1, 2, 3, 4. <p> +To change the value of the 5th element we would code: +<pre> + main() + { + int Count[5]; + Count[4] = 20; /* code 4 to update the 5th element */ + } +</pre> + +If we want to initalise 'Count' at <A HREF="../glossary.html#definition">definition</A> we can say: +<pre> + main() + { + int i; + int Count[5]={10, 20, 30}; + for (i=0; i< 5; i++) + { + printf("%d ", Count[i]); + } + puts(""); + } +</pre> + +The result will be: +<pre> + 10 20 30 0 0 +</pre> +We can see from the example above that the elements that have NOT been +initalised +have been set to zero.<p> +One last thing to show you. If all the elements are being +initialized when the variable is being defined, the compiler can work out +the number of elements for you. So this example will create an array +with 3 elements. +<pre> + main() + { + int i; + int Count[]={10, 20, 30}; + } +</pre> + +Don't forget, all the stuff so far also applies to <b>float</b>. +<p> + +<a name="twod"> +<hr> +<h2>Two dimensional <b>int</b> and <b>float</b> arrays.</h2> + +C does not actually support multi-dimensional arrays, but you can +emulate them. +<pre> + main() + { + int Count[5]; + int Matrix[10][4]; + } +</pre> +<b>Count</b> has been seen before, it defines an array of 5 elements.<p> +<b>Matrix</b> is defined as 10 arrays, all with 4 elements.<p> +To initalise <b>Matrix</b> at definition, you would code the following. +<pre> + main() + { + int Matrix[4][2]={{1, 2}, + {3, 4}, + {5, 6}, + {7, 8}}; + } +</pre> +Dont forget the last element will be <b>Matrix[3][1]</b> +<p> + +<a name="char"> +<hr> +<h2>char arrays.</h2> + +<b>char</b> arrays work in the same way as <b>int</b> and <b>float</b> +<pre> + main() + { + char Letter; + char Letters[10]; + } +</pre> +'Letter' can only hold one character but 'the 'Letters' array could hold 10. +It is important to think of 'char' as an array and NOT a string.<p> +To initalise 'char' variables you can use the following syntax. +<pre> + main() + { + char Letter='x'; + char Letters[10]='f','a','x',' ','m','o','d','e','m','\0'; + char Text[10]="fax modem"; + } +</pre> +Note that the double quotes mean 'text string' and so they will add the +<a href=../SYNTAX/null.html>NULL</a> +automatically. This is the only time that text can be loaded into an array +in this way. If you want to change the contents of the array you should use +the function <a href=../FUNCTIONS/strcpy.html>strcpy</a>. +<p> + +<a name="chard"> +<hr> +<h2>Two dimensional char arrays.</h2> + +Two dimensional arrays are a different kettle of fish! We can follow the +rules above to define the array like this. +<pre> + main() + { + char Colours[3][6]={"red","green","blue"}; + + printf ("%c \n", Colours[0][0]); /* O/P 'r' */ + printf ("%s \n", Colours[1]); /* O/P 'green' */ + } +</pre> + +The example above has reserved 18 consecutive bytes and created three +pointers into them. +<pre> + + --------------------- + |red \0green\0blue \0| + --------------------- + A A A + | | | + Colours[0] ---- | | + Colours[1] ----------- | + Colours[2] ------------------ + +</pre> +<center> +<p> +<font size= +2> +<a href=pointers.html>click here</a> for chat on pointers. +</font> +</center> +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/assignment.html b/reference/C/CONCEPT/assignment.html new file mode 100644 index 0000000..5985d5b --- /dev/null +++ b/reference/C/CONCEPT/assignment.html @@ -0,0 +1,91 @@ +<title>Assignment operators.</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Assignment operators.</h1> +</center> +<hr> + +C has the following assignement operators: +<pre> + = += -= *= /= %= <<= >>= &= ^= |= +</pre> += is the obvious one. It takes the result of the expression on the right +and assigns it to the variable on the left (lvalue). +<pre> + main () + { + int a, b=4, c=10; + a = b + c; + } +</pre> +I know this is stating the obvious, but: +<ol> +<li><b>b</b> is assigned the value 4 +<li><b>c</b> is assigned the value 10 +<li><b>a</b> is assigned the result of b plus C (14). +</ol> + +<hr> +All the other operators act in a simular way. If you find yourself +coding the example on the left, it could be changed to the example on +the right. +<pre> + main () main() + { { + int a=4; int a=4; + a = a * 4; a *= 4; + } } +</pre> +The rule is as follows: +<p> +The lvalue is multiplied by the rvalue and the result assigned to the +lvalue. +<p> +Here is another example. +<pre> + main() main() + { { + int a=10, b=2; int a=10, b=2; + a /= b * 5; a = a / (b*5); + } } +</pre> +Again both preduce the same answer (1). +<p> +<hr> + +<img src=../../GRAPHICS/whiteball.gif> +<a href="inc_dec.html">Increment (++) and Decrement (--)</a><br> + +<img src=../../GRAPHICS/whiteball.gif> +<a href="bit_shift.html">Bit shifting ( >>= <<= )</a><br> + +<img src=../../GRAPHICS/whiteball.gif> +<a href="precedence.html">Operator precedence table.</a> +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/bit_shift.html b/reference/C/CONCEPT/bit_shift.html new file mode 100644 index 0000000..507400c --- /dev/null +++ b/reference/C/CONCEPT/bit_shift.html @@ -0,0 +1,219 @@ +<title>Bitwise operations</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Bitwise operations</h1> +</center> +<hr> + +<p> +Bitwise operators include: +<p> +<center> +<table border=2 width=40% bgcolor=ivory> +<tr align=center><td>&</td> <td><a href="#aox">AND</a></td></tr> +<tr align=center><td>&=</td> <td><a href="#aox">AND</a></td></tr> +<tr align=center><td>|</td> <td><a href="#aox">OR</a></td></tr> +<tr align=center><td>|=</td> <td><a href="#aox">OR</a></td></tr> +<tr align=center><td>^</td> <td><a href="#aox">XOR</a></td></tr> +<tr align=center><td>~</td> <td><a href="#one">one's compliment</a></td></tr> +<tr align=center><td><<</td> <td><a href="#shift">Shift Left</a></td></tr> +<tr align=center><td>>></td> <td><a href="#shift">Shift Right</a></td></tr> +<tr align=center align=center><td><<=</td> <td><a href="#shift">Shift Left</a></td></tr> +<tr align=center><td>>>=</td><td><a href="#shift">Shift Right</a></td></tr> +</table> +</center> +<p> + +<a name=aox> +<hr> +<h2>AND OR and XOR</h2> + +These require two operands and will perform bit comparisions. +<p> +<b>AND &</b> +will copy a bit to the result if it exists in both operands. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int a = 60; /* 60 = 0011 1100 */ + unsigned int b = 13; /* 13 = 0000 1101 */ + unsigned int c = 0; + + c = a & b; /* 12 = 0000 1100 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +<b>OR |</b> will copy a bit if it exists in eather operand. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int a = 60; /* 60 = 0011 1100 */ + unsigned int b = 13; /* 13 = 0000 1101 */ + unsigned int c = 0; + + c = a | b; /* 61 = 0011 1101 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +<b>XOR ^</b> copies the bit if it is set in one operand (but not both). +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int a = 60; /* 60 = 0011 1100 */ + unsigned int b = 13; /* 13 = 0000 1101 */ + unsigned int c = 0; + + c = a ^ b; /* 49 = 0011 0001 */ + } + +</pre> +</td></tr> +</table> +</center> + +<p> +<a name=one> +<hr> +<h2>Ones Complement</h2> + +This operator is unary (requires one operand) and has the efect of +'flipping' bits. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int Value=4; /* 4 = 0000 0100 */ + + Value = ~ Value; /* 251 = 1111 1011 */ + + } + +</pre> +</td></tr> +</table> +</center> +<p> + + +<p> +<a name=shift> +<hr> +<h2>Bit shift.</h2> +The following <a href="../CONCEPT/expressions.html">operators</a> +can be used for shifting bits left or right. +<p> +<center> +<table border=2 width=50% bgcolor=ivory> +<tr align=center> +<td width=25%> << </td> +<td width=25%> >> </td> +<td width=25%> <<= </td> +<td width=25%> >>= </td> +</tr> +</table> +</center> +<p> +The left operands value is moved left or right by the number of bits specified +by the right operand. For example: +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int Value=4; /* 4 = 0000 0100 */ + unsigned int Shift=2; + + Value = Value << Shift; /* 16 = 0001 0000 */ + + Value <<= Shift; /* 64 = 0100 0000 */ + + printf("%d\n", Value); /* Prints 64 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +Usually, the resulting 'empty' +bit is assigned ZERO. +Please use +<a href="data_types.html#modifier">unsigned</a> +variables with these operators to avoid unpredictable +results. +<p> +<hr> +<h2>Examples:</h2> +<a href="../EXAMPLES/and.c"><img src=../../GRAPHICS/computer.gif></a> AND<br> +<a href="../EXAMPLES/or.c"><img src=../../GRAPHICS/computer.gif></a> OR<br> +<a href="../EXAMPLES/bit_shift.c"><img src=../../GRAPHICS/computer.gif></a> Bit shifting. +<hr> +<h2>Problem:</h2> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../PROBLEMS/problems.html#binary">Bit shifting problem.</a> +<hr> +<h2>See Also:</h2> +<img src=../../GRAPHICS/whiteball.gif> +All the other <a href="expressions.html#bit">Expressions and operators</a>.<br> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../CONCEPT/precedence.html">Operator precedence.</a><br> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../CONCEPT/assignment.html">Assignment Operators</a>. +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> + diff --git a/reference/C/CONCEPT/bitsnbytes.html b/reference/C/CONCEPT/bitsnbytes.html new file mode 100644 index 0000000..a271c9d --- /dev/null +++ b/reference/C/CONCEPT/bitsnbytes.html @@ -0,0 +1,84 @@ +<title>Bits 'n Bytes</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Bits 'n Bytes.</h1> +</center> +<hr> + +This is basic Computer Science but its worth restating the basics +sometimes. +<p> +<hr> +<h2>bits</h2> + +A bit is the smallest component in computer memory, it has +two states, either ON or OFF. These states are represented as 1 or 0 +and thus everything is based on binary arithmatic. +<pre> +Off == 0 +On == 1 +</pre> +<p> +<hr> +<h2>Bytes</h2> + +For convinence, bits are grouped into blocks of 8, these blocks +are called Bytes. +An integer byte can store any value from 0 -> 255. + + ------------------------- + 128 64 32 16 8 4 2 1 + ------------------------- + 8 4 2 1 8 4 2 1 + ------------------------- + F F + ------------------------- + +<h2>KiloBytes</h2> + +This is a thousand bytes. The exact value is 2 to the power of <superscript>10</superscript> +or 1,024 + +<h2>MegaBytes</h2> +This is a Million bytes. The exact value is 2 to the power of <superscript>20</superscript> +or 1,048,576 + +<h2>GigaBytes</h2> + +The exact value is 2 to the power of <superscript>30</superscript> +or 1,073,741,824 + +<h2>TeraBytes</h2> + +The exact value is 2 to the power of <superscript>40</superscript> +or 1,099,511,627,776 (big....) + +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/bitwise.html b/reference/C/CONCEPT/bitwise.html new file mode 100644 index 0000000..82c2aca --- /dev/null +++ b/reference/C/CONCEPT/bitwise.html @@ -0,0 +1,231 @@ +<title>Bitwise operations</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Bitwise operations</h1> +</center> +<hr> + +<p> +Bitwise operators include: +<p> +<center> +<table border=2 width=40% bgcolor=ivory> +<tr align=center><td>&</td> <td><a href="#aox">AND</a></td></tr> +<tr align=center><td>&=</td> <td><a href="#aox">AND</a></td></tr> +<tr align=center><td>|</td> <td><a href="#aox">OR</a></td></tr> +<tr align=center><td>|=</td> <td><a href="#aox">OR</a></td></tr> +<tr align=center><td>^</td> <td><a href="#aox">XOR</a></td></tr> +<tr align=center><td>^=</td> <td><a href="#aox">XOR</a></td></tr> +<tr align=center><td>~</td> <td><a href="#one">one's compliment</a></td></tr> +<tr align=center><td><<</td> <td><a href="#shift">Shift Left</a></td></tr> +<tr align=center><td><<</td> <td><a href="#shift">Shift Left</a></td></tr> +<tr align=center align=center><td>>>=</td> <td><a href="#shift">Shift Right</a></td></tr> +<tr align=center><td>>>=</td><td><a href="#shift">Shift Right</a></td></tr> +</table> +</center> +<p> + +<a name=aox> +<hr> +<h2>AND OR and XOR</h2> + +These require two operands and will perform bit comparisions. +<p> +<b>AND &</b> +will copy a bit to the result if it exists in both operands. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int a = 60; /* 60 = 0011 1100 */ + unsigned int b = 13; /* 13 = 0000 1101 */ + unsigned int c = 0; + + c = a & b; /* 12 = 0000 1100 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +<b>OR |</b> will copy a bit if it exists in eather operand. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int a = 60; /* 60 = 0011 1100 */ + unsigned int b = 13; /* 13 = 0000 1101 */ + unsigned int c = 0; + + c = a | b; /* 61 = 0011 1101 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +<b>XOR ^</b> copies the bit if it is set in one operand (but not both). +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int a = 60; /* 60 = 0011 1100 */ + unsigned int b = 13; /* 13 = 0000 1101 */ + unsigned int c = 0; + + c = a ^ b; /* 49 = 0011 0001 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +<img src=../../GRAPHICS/computer.gif alt="o"> +<a href=../EXAMPLES/swap.c>XOR example program</a> which swaps the contents of two variables. + +<p> +<a name=one> +<hr> +<h2>Ones Complement</h2> + +This operator is unary (requires one operand) and has the efect of +'flipping' bits. +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int Value=4; /* 4 = 0000 0100 */ + + Value = ~ Value; /* 251 = 1111 1011 */ + + } + +</pre> +</td></tr> +</table> +</center> + +<p> +<a name=shift> +<hr> +<h2>Bit shift.</h2> +The following <a href="../CONCEPT/expressions.html">operators</a> +can be used for shifting bits left or right. +<p> +<center> +<table border=2 width=50% bgcolor=ivory> +<tr align=center> +<td width=25%> << </td> +<td width=25%> >> </td> +<td width=25%> <<= </td> +<td width=25%> >>= </td> +</tr> +</table> +</center> +<p> +The left operands value is moved left or right by the number of bits specified +by the right operand. For example: +<p> +<center> +<table border=2 bgcolor=ivory> +<tr><td> +<pre> + + main() + { + unsigned int Value=4; /* 4 = 0000 0100 */ + unsigned int Shift=2; + + Value = Value << Shift; /* 16 = 0001 0000 */ + + Value <<= Shift; /* 64 = 0100 0000 */ + + printf("%d\n", Value); /* Prints 64 */ + } + +</pre> +</td></tr> +</table> +</center> +<p> +Usually, the resulting 'empty' +bit is assigned ZERO. +Please use +<a href="data_types.html#modifier">unsigned</a> +variables with these operators to avoid unpredictable +results. +<hr> +<h2>Examples:</h2> +<img src=../../GRAPHICS/computer.gif> +<a href="../EXAMPLES/and.c">AND</a><br> +<img src=../../GRAPHICS/computer.gif> +<a href="../EXAMPLES/or.c">OR</a><br> +<img src=../../GRAPHICS/computer.gif> +<a href="../EXAMPLES/bit_shift.c">Bit shifting.</a> +<hr> +<h2>Problem:</h2> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../PROBLEMS/problems.html#binary">Bit shifting problem.</a> +<hr> +<h2>See Also:</h2> +<img src=../../GRAPHICS/whiteball.gif> +All the other <a href="expressions.html#bit">Expressions and operators</a>.<br> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../CONCEPT/precedence.html">Operator precedence.</a><br> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../CONCEPT/assignment.html">Assignment Operators</a>. +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> + + + + + + + + + diff --git a/reference/C/CONCEPT/cast.html b/reference/C/CONCEPT/cast.html new file mode 100644 index 0000000..6535052 --- /dev/null +++ b/reference/C/CONCEPT/cast.html @@ -0,0 +1,75 @@ +<head> +<title>cast</title> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>To cast, casting</h1> +</center> +<hr> + +If you want to change the +<a href="../CONCEPT/data_types.html">datatype</a> of a variable +you have to use a technic called <b>cast</b>. For example if want to +change an <a href="../CONCEPT/data_types.html#int">int</a> to a +<a href="../CONCEPT/data_types.html#float">float</a> +you could use the following syntax: +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr> +<td> +<pre> + + main() + { + int var1; + float var2; + + var2 = (float)var1; + } +</pre> +</td> +</tr> +</table> +</center> +<p> +As it happens this example would never be used in practice because C +would perform the conversion automatically. + +What this example does show is the cast operator<b> () </b>. This states, +the result of the expression (in this case <b>var1</b>) is to be a +data type of <a href="../CONCEPT/data_types.html#float">float</a>. +<p> +<hr> +<h2>See Also:</h2> + +<a href=../../CPLUSPLUS/CONCEPT/cast.html> C++ changes to cast.</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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/cmdline.html b/reference/C/CONCEPT/cmdline.html new file mode 100644 index 0000000..2dc85e7 --- /dev/null +++ b/reference/C/CONCEPT/cmdline.html @@ -0,0 +1,48 @@ +<title>Command line arguments</title> +<body bgcolor="ffffcc"> +<hr> +<center> +<h1>Command line arguments</h1> +</center> +<hr> + + + +<hr> +<h2>Examples:</h2> +<img src=../../GRAPHICS/computer.gif> +<a href="../EXAMPLES/command_line.c"> Example using argc and argv</a> +<br> +<img src=../../GRAPHICS/computer.gif> +<a href="../CONTRIB/SNIP/cmdline.c"> Bob Stout's example.</a> +<hr> +<h2>See Also:</h2> +<img src=../../GRAPHICS/whiteball.gif> +<a href="../FUNCTIONS/getopt.html">getopt</a> function. +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/constants.html b/reference/C/CONCEPT/constants.html new file mode 100644 index 0000000..e2a7778 --- /dev/null +++ b/reference/C/CONCEPT/constants.html @@ -0,0 +1,143 @@ +<title>Constants</title> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>Constants</h1></center> +<hr> +Be sure you understand the difference between a 'constant' and a +<a href=../glossary.html#declaration>declaration</a>. +A constant has a value that cannot be changed. For example: +<pre> + + 1234 + 'x' + 9.89 + "String" + +</pre> +Constants are used to assign a value to a variable. E.G +<pre> + int i; /* declare a variable called 'i' */ + i=1234; /* assign the constant value 1234 to + * the variable 'i' */ + i++; /* Change the value of the variable. */ +</pre> +<ul> +<li><a href="#int">Integer constants.</a> +<li><a href="#float">Floating point constants.</a> +<li><a href="#char">Character constants.</a> +<li><a href="#str">String constants.</a> +</ul> +<hr> +<h2><a name=int>Integer constants.</h2> +Interger constants can be expressed in the following ways. +<pre> + 1234 (decimal) + 0xff (Hexidecimal) + 0100 (Octal) + '\xf' (Hex character) +</pre> +Examples of their use are: +<pre> + int i=255; /* i assigned the decimal value of 255 */ + + i-=0xff /* subtract 255 from i */ + + i+=010 /* Add Octal 10 (decimal 8) */ + + /* Print 15 - there are easier ways... */ + printf ("%i \n", '\xf'); + +</pre> +Integer constants are assumed to have a datatype of +<a href=data_types.html#int> int</a>, if it will not fit into an 'int' +the compiler will assume the constant is a +<a href=data_types.html#modifier>long</a>. You may also force the +compiler to use 'long' by putting an 'L' on the end of the +integer constant. +<pre> + 1234L /* Long int constant (4 bytes) */ +</pre> +The other modifier is 'U' for Unsigned. +<pre> + 1234U /* Unsigned int */ +</pre> +and to complete the picture you can specify 'UL' +<pre> + 1234UL /* Unsigned long int */ +</pre> + +<hr> +<h2><a name=float>Floating point constants.</h2> +Floating point constants contain a decimal point or exponent. By default +they are <a href=data_types.html#double>double</a>. +<pre> + 123.4 + 1e-2 + + +<hr> +</pre> +<h2><a name=char>Chararacter constants.</h2> +Are actually integers. +<pre> + 'x' + '\000' + '\xhh' + + <a href=../FUNCTIONS/escape.html>escape sequences</a> + +</pre> + +<hr> +</pre> +<h2><a name=str>String constants.</h2> + +Strings do not have a <a href=data_types.html>datatype</a> of their own. +They are actually a sequence of char items terminated with a +<a href=../SYNTAX/null.html>\0</a>. A string can be accessed with a +<b>char</b> pointer. +<p> +An example of a string would be: +<pre> + + char *Str = "String Constant"; + +</pre> + +See the discussion on <a href=../CONCEPT/string.html> +strings</a> for more information. +<p> + +<hr> +<h2>Also see:</h2> +<ul> +<li><a href=../SYNTAX/define_preprocessor.html>#define</a> +<li><a href=../CONCEPT/string.html>Strings</a> +</ul> +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/data_types.html b/reference/C/CONCEPT/data_types.html new file mode 100644 index 0000000..1c32515 --- /dev/null +++ b/reference/C/CONCEPT/data_types.html @@ -0,0 +1,218 @@ +<title>C Data types</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>C Data types.</h1> +</center> +<hr> +<p> + +<h2>Variable definition</h2> +C has a concept of '<i>data types</i>' which are used to +<a href="../glossary.html#definition">define</a> a variable +before its use. <p> +The definition of a variable will assign storage for the variable and +define the type of data that will be held in the location.<p> +So what data types are available? +<p> +<table border=1 bgcolor=ivory width=80%> +<tr align=center> +<td><a href="#int">int</a> +<td><a href="#float">float</a> +<td><a href="#double">double</a> +<td><a href="#char">char</a> +<td><A HREF="../SYNTAX/void.html">void</A> +<td><A HREF="../SYNTAX/enum.html">enum</A> +</table> +<p> +Please note that there is not a boolean data type. C does not have the +traditional view about logical comparison, but thats another story.<p> +<font color="brown"> +Recent C++ compilers do have a <a href="../../CPLUSPLUS/SYNTAX/bool.html">boolean</a> datatype. +<p> +</font> +<hr> +<h2><a name="int">int - data type</h2> +<b>int</b> is used to define integer numbers. +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr><td> +<pre> + + { + int Count; + Count = 5; + } +</pre> +</td></tr></table> +</center> +<p> +<hr> +<h2><a name="float">float - data type</h2> +<b>float</b> is used to define floating point numbers. +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr><td> +<pre> + + { + float Miles; + Miles = 5.6; + } +</pre> +</td></tr></table> +</center> +<p> +<hr> +<h2><a name="double">double - data type</h2> +<b>double</b> is used to define BIG floating point numbers. It reserves twice +the storage for the number. On PCs this is likely to be 8 bytes. +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr><td> +<pre> + + { + double Atoms; + Atoms = 2500000; + } +</pre> +</td></tr></table> +</center> +<p> +<hr> +<h2><a name="char">char - data type</h2> +<b>char</b> defines characters. +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr><td> +<pre> + + { + char Letter; + Letter = 'x'; + } +</pre> +</td></tr></table> +</center> +<p> +<a name="modifier"> +<hr> +<h2>Modifiers</h2> +The three data types above have the following modifiers. +<p> +<ul> +<li>short +<li>long +<li>signed +<li>unsigned +</ul> + +The modifiers define the amount of storage allocated to the variable. +The amount of storage allocated is not cast in stone. ANSI has the +following rules:<p> +<p> +<center> +<table border=1 width="80%" bgcolor="ivory"> +<tr><td> +<pre> + + short int <= int <= long int + float <= double <= long double +</pre> +</td></tr></table> +</center> +<p> +What this means is that a 'short int' should assign less than or the same +amount of storage as an 'int' and the 'int' should be less or the same bytes +than a 'long int'. What this means in the real world is: +<p> +<table border=2 width="100%" bgcolor="ivory"> +<tr><td> +<pre> + + Type Bytes Bits Range +</pre> +</td></tr> +<tr><td> +<pre> + + short int 2 16 -16,384 -> +16,383 (16kb) + unsigned short int 2 16 0 -> +32,767 (32Kb) + unsigned int 4 16 0 -> +4,294,967,295 ( 4Gb) + int 4 32 -2,147,483,648 -> +2,147,483,647 ( 2Gb) + long int 4 32 -2,147,483,648 -> +2,147,483,647 ( 2Gb) + signed char 1 8 -128 -> +127 + unsigned char 1 8 0 -> +255 + float 4 32 + double 8 64 + long double 12 96 +</pre> +</td></tr></table> +<p> +These figures only apply to todays generation of PCs. Mainframes and +midrange machines could use different figures, but would still comply +with the rule above.<p> +You can find out how much storage is allocated to a data type by using +the <a href="../SYNTAX/sizeof.html">sizeof</a> operator. +<a name="qualifier"> +<hr> +<h2>Qualifiers</h2> +<p> +<ul> +<li><a href="../SYNTAX/const.html">const</a> +<li><a href="../SYNTAX/volatile.html">volatile</a> +</ul> + +The <i>const</i> qualifier is used to tell C that the variable value can not +change after initialisation.<p> + + const float pi=3.14159; + +<p> +<i>pi</i> cannot be changed at a later time within the program.<p> +Another way to define constants is with the +<a href="../SYNTAX/define_preprocessor.html">#define</a> preprocessor which +has the advantage that it does not use any storage (but who counts bytes + these days?).<p> +<hr> +<h2>See also:</h2> +<a href="type_conv.html">Data type conversion</a> +<p> +<a href="storage_class.html">Storage classes.</a> +<p> +<a href="cast.html">cast</a> +<p> +<a href="../SYNTAX/typedef.html">typedef</a> keyword. + +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/expressions.html b/reference/C/CONCEPT/expressions.html new file mode 100644 index 0000000..a3dac05 --- /dev/null +++ b/reference/C/CONCEPT/expressions.html @@ -0,0 +1,135 @@ +<head> +<title>C operators</title> +</head> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>C Operators/Expressions</h1> +</center> +<hr> +<p> + +Operators are used with +<a href="../glossary.html#operand">operands</a> +to build expressions. For example the +following is an expression containing two operands and one oprator. + +<pre> + 4 + 5 +</pre> + +The following list of operators is probably not complete but does highlight +the common +operators and a few of the outrageous ones.... +<p> +C contains the following operator groups. +<ul> +<li><a href="#arith">Arithmetic</a> +<li><a href="#ass">Assignment</a> +<li><a href="#rel">Logical/relational</a> +<li><a href="#bit">Bitwise</a> +<li><a href="#star">Odds and ends!</a> +<p> +<li><a href="precedence.html">Operator precedence table.</a> +</ul> +The order (precedence) that operators are evaluated can be seen +<a href="precedence.html">here.</a> + +<h2><a name=arith>Arithmetic</h2> +<pre> + + + - + / + * + % <a href="../EXAMPLES/modulo.c">modulo</a> + -- <a href="inc_dec.html">Decrement</a> (post and pre) + ++ <a href="inc_dec.html">Increment</a> (post and pre) +</pre> +<h2><a name=ass>Assignment</h2> +These all perform an arithmetic operation on the lvalue and assign the +result to the lvalue. So what does this mean in English? Here is an example: +<pre> counter = counter + 1; </pre> +can be reduced to +<pre> counter += 1; </pre> +Here is the full set. +<pre> + = + *= <a href="assignment.html">Multiply</a> + /= <a href="assignment.html">Divide.</a> + %= <a href="assignment.html">Modulus.</a> + += <a href="assignment.html">add.</a> + -= <a href="assignment.html">Subtract.</a> + <<= <a href="assignment.html">left shift.</a> + >>= <a href="assignment.html">Right shift.</a> + &= <a href="assignment.html">Bitwise AND.</a> + ^= <a href="assignment.html">bitwise exclusive OR (XOR).</a> + |= <a href="assignment.html">bitwise inclusive OR.</a> +</pre> +<h2><a name=rel>Logical/Relational</h2> +<pre> + == Equal to + != Not equal to + > + < + >= + <= + && <a href="../SYNTAX/logical.html">Logical AND</a> + || <a href="../SYNTAX/logical.html">Logical OR</a> + ! <a href="../SYNTAX/logical.html">Logical NOT</a> +</pre> +<h2><a name=bit>Bitwise</h2> +<pre> + & <a href="../CONCEPT/bitwise.html">AND (Binary operator)</a> + | <a href="../CONCEPT/bitwise.html">inclusive OR</a> + ^ <a href="../CONCEPT/bitwise.html">exclusive OR</a> + << <a href="../CONCEPT/bit_shift.html">shift left</a>. <font color=brown>C ++ use of <a href=../../CPLUSPLUS/SYNTAX/ops.html><<</a></font> + + >> <a href="../CONCEPT/bit_shift.html">shift right</a>. <font color=brown>C ++ use of <a href=../../CPLUSPLUS/SYNTAX/ops.html>>></a></font> + ~ <a href="../CONCEPT/bitwise.html">one's complement</a> +</pre> +<a name=comma> +<h2><a name=star>Odds and ends!</h2> +<pre> + sizeof() <a href="../SYNTAX/sizeof.html">size</a> of objects and <a href="data_types.html">data types</a>. + <a href="../FUNCTIONS/strlen.html">strlen</a> may also be of interest. + & <a href="../EXAMPLES/address.c">Address of</a> (Unary operator) + * <a href="../EXAMPLES/address.c">pointer</a> (Unary operator) + ? <a href="../SYNTAX/conditional.html">Conditional expressions</a> + : <a href="../SYNTAX/conditional.html">Conditional expressions</a> + , <a href="../SYNTAX/comma.html">Series operator.</a> +</pre> +<hr> +<p> +<h2>C++ Extensions</h2> + +<font color=brown> +Read about :: >> and << in the world of C++ +<a href=../../CPLUSPLUS/SYNTAX/ops.html>here!</a> +</font> +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/inc_dec.html b/reference/C/CONCEPT/inc_dec.html new file mode 100644 index 0000000..dd8216b --- /dev/null +++ b/reference/C/CONCEPT/inc_dec.html @@ -0,0 +1,84 @@ +<title>Increment and decrement.</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>Increment and decrement.</h1> +</center> +<hr> + +The traditional method of incrementing numbers is by coding something like: +<pre> + a = a + 1; +</pre> +Within C, this syntax is valid but you can also use the ++ operator to perform +the same function. +<pre> + a++; +</pre> +will also add 1 to the value of <b>a</b>. +By using a simular syntax you can also decrement a variable as shown below. +<pre> + a--; +</pre> +These operators can be placed as a prefix or post fix as below: +<pre> + a++; ++a; +</pre> +When used on their own (as above) the prefix and postfix have the same effect +BUT within an expression there is a subtle difference....<p> + +<ol> +<li>Prefix notation will increment the variable BEFORE the +expression is evaluated. +<li>Postfix notation will increment AFTER the expression evaluation. +</ol> + +Here is an example: +<pre> + main() main() + { { + int a=1; int a=1; + printf(" a is %d", ++a); printf(" a is %d", a++); + } } + +</pre> + +In both examples, the final value of <b>a</b> will be 2. BUT the first +example will print 2 and the second will print 1. + +<hr> +<img src=../../GRAPHICS/computer.gif> +<a href="../EXAMPLES/inc_dec.c"> Example program.</a><br> + +<img src=../../GRAPHICS/whiteball.gif> +<a href="../CONCEPT/expressions.html">Other operators.</a><br> + +<img src=../../GRAPHICS/whiteball.gif> +<a href="../CONCEPT/precedence.html">Operator precedence table.</a> +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/pointers.html b/reference/C/CONCEPT/pointers.html new file mode 100644 index 0000000..4830b09 --- /dev/null +++ b/reference/C/CONCEPT/pointers.html @@ -0,0 +1,559 @@ +<title>Pointers</title> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>Pointers.</h1></center> +<hr> +<p> +Pointers are at the heart of C. When you crack this subject, you have got the worst +of C behind you. Before you tackle pointers though, you should get a grip +on <a href=arrays.html>arrays</a>.<p> +<ul> +<li><a href="#first">First principles.</a> +<li><a href="#def">Definition of a pointer.</a> +<li><a href="string.html">Pointers to strings.</a> +<li><a href="#arrays">Pointers to arrays.</a> +<li><a href="#compare">Char arrays verses char pointers.</a> +<li><a href="#void">Void pointers.</a> +<li><a href="#ptrs">Pointers to pointers.</a> +<li><a href="#functions">Pointers to functions.</a> +<li><a href=../MISC/linklists.html>Linked lists.</a> +</ul> +<a name=string> +<a name=basic> +<a name=first> +<hr> +<h2>First Principles.</h2> +To understand pointers, it may be worth understanding how normal +variables are stored. If you disagree, <A HREF="#def">Click here</A> +to move on. +<p> +What does the following program realy mean? +<p> +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int Length; + } +</pre> +</td> +</tr> +</table> +<p> +In my mind, it means, reserve enough storage to hold an integer and assign the variable +name 'Length' to it. The data held in this storage is undefined. +Graphically it looks like: +<pre> + + (Address) (Data) + ---- ---- + | F1 | <------- Length + |----|----| + | F2 | | + |----|----| + | F3 | | + |----|----| + | F4 | | + --------- + +</pre> +To put a known value into 'Length' we code, +<p> +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int Length; + Length = 20; + } +</pre> +</td> +</tr> +</table> +<p> +the deciamal value 20 (Hex 14) is placed into the storage location. +<pre> + + (Address) (Data) + ---- ---- + | F1 | 00 <------- Length + |----|----| + | F2 | 00 | + |----|----| + | F3 | 00 | + |----|----| + | F4 | 14 | + --------- + +</pre> +Finally, if the program is expanded to become +<p> +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int Length; + + Length = 20; + + <A HREF="../FUNCTIONS/printf.html">printf</a>("Length is %d\n", Length); + printf("Address of Length is %p\n", &Length); + } + +</pre> +</td> +</tr> +</table> +<p> +The output would look something like this ..... +<pre> + + Length is 20 + Address of Length is 0xF1 + +</pre> + +Please note the '&Length' on the second printf statement. +The <b>&</b> means <b>address of</b> Length. +If you are happy with this, you should push onto the pointers below. +<p> +<a name=def> +<hr> +<h2>Pointer definition.</h2> + +<b>A pointer contains an <a href=../glossary.html#address>address</a> that points + +to data.</b> +<p> +An example of code <a href=../glossary.html#definition>defining</a> a pointer could be... +<p> +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int *Width; + } + +</Pre> +</td> +</tr> +</table> +<p> +A graphical representation could be... +<pre> + + (Address) (Data) + ---- ---- + | F1 | <------- Width + |----|----| + | F2 | | + |----|----| + | F3 | | + |----|----| + | F4 | | + --------- + +</pre> +So far, this variable looks the same as above, + the value stored at 'Width' is unknown. +To place a value in 'Width' you could code. +<p> +<Table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int *Width; /* 1 */ + + Width = (int *)malloc(sizeof(int)); /* 2 */ + + *Width = 34; /* 3 */ + } + +</pre> +</td> +</tr> +</table> +<pre> + + (Address) (Data) + ---- ---- + | F1 | 00 <------- Width + |----|----| (Data) (Adress) + | F2 | 00 | --------- + |----|----| -------> 00 | D1 | + | F3 | 00 | | |----|----| + |----|----| *Width| | 00 | D2 | + | F4 | D1 | ------- |----|----| + --------- | 00 | D3 | + |----|----| + | 22 | D4 | + --------- + +</pre> + +Statements 2 and 3 are important here: +<p> +2) The <a href="../FUNCTIONS/malloc.html">malloc</a> function reserves some storage and puts the address of the +storage into Width. +<p> +3) *Width puts a value into the storage pointed to by Width. +<p> + +Unlike the +<a href="#first">Length = 20</a> example above, the storage pointed to by 'Width' +does NOT contain 34 (22 in Hex), it contains the address where the value +34 can be found. +The final program is... +<p> +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + int *Width; + + Width = (int *)malloc(sizeof(int)); + *Width = 34; + + printf(" Data stored at *Width is %d\n", *Width); + printf(" Address of Width is %p\n", &Width); + printf("Address stored at Width is %p\n", Width); + } + +</pre> +</tr> +</td> +</table> +<p> +The program would O/P something like. +<p> +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + Data stored at *Width is 34 + Address of Width is 0xF1 + Address stored at Width is 0xD1 + +</pre> +</td> +</td> +</table> + +<p> +<a name=why>A pointer can point to any data type, ie +<a href=data_types.html#int>int</a>, +<a href=data_types.html#float>float</a>, +<a href=data_types.html#char>char</a>. +When <a href=../glossary.html#definition>defining</a> a pointer you +place an <b>*</b> (asterisk) character +between the data type and the variable name, here are a few examples. +<p> +<table border=2 width=100% bgcolor=ivory> +<tr><td> +<pre> + + main() + { + int count; /* an integer variable */ + int *pcount; /* a pointer to an integer variable */ + float miles; /* a floating point variable. */ + float *m; /* a pointer */ + char ans; /* character variable */ + char *charpointer; /* pointer to a character variable */ + } + +</pre> +</td></tr></table> +<p> + + +<p> + +<a name=arrays> +<hr> +<h2>Pointers to arrays</h2> +When looking at +<a href=arrays.html>arrays</a> we had a program that accessed data within a +two dimensional character array. This is what the code looked like. + +<pre> + main() + { + char colours[3][6]={"red","green","blue"}; + } +</pre> +The code above has defined an array of 3 elements, each pointing to 6 +character strings. +You can also code it like this. Which is actually more descriptive +because it indicates what is actually going on in storage. +<pre> + main() + { + char *colours[]={"red","green","blue"}; + } +</pre> + +Graphically it looks like this: +<p> +<table border=2 width=100% bgcolor=ivory> +<tr><td> +<pre> + +<font color="gray"> + + + colours *colours *(colours+2) **colours + | | | | + | | | | + V V V | </font> + --- ----------- <font color="gray"> | </font> + | |---->| | | | <font color="gray"> | </font> + --- ----------- <font color="gray"> | </font> + | | | <font color="gray"> V </font> + | | | ----------------------- + --------------->| r | e | d | | | | + | | ----------------------- + | | + | | ----------------------- + ---|-------->| g | r | e | e | n | | + | ----------------------- + | + | ----------------------- + -------->| b | l | u | e | | | + ----------------------- +<font color="gray"> A A + | | + | | + **(colours+2) *(*(colours+2)+3) +</font> +</pre> +</td></tr></table> +<p> +<pre> + printf("%s \n", colours[1]); + printf("%s \n", *(colours+1)) +</pre> +will both return <b>green</b>. +<p> + +<a name=compare> +<hr> +<h2>Char Arrays verses Char pointers</h2> + +What is the difference +between these two lumps of code? +<p> +<table border=2 width=100% bgcolor=ivory> +<tr><td> +<pre> + + main() + { + char colour[]="red"; + printf("%s \n",colour); + } + +</pre> +</td><td> +<pre> + + main() + { + char *colour="red"; + printf("%s \n",colour); + } + +</pre> +</td></tr></table> +<p> +The answer is, NOTHING! They both print the word +<b>red</b> because in both cases 'printf' is being passed a pointer to a +string. +<p> +An <a href=arrays.html>array</a> of 4 bytes is +reserved and the text 'red' placed +into the storage array. The contents of the array can be chaged later +BUT on the left, the size of the array is fixed. +<p> +Here is a picture of the example on the right. The 'r' of 'red' is stored +at address 10, the 'e' is at address 11 etc. + +<p> +<img src=../../GRAPHICS/ptr.gif> +<p> +At this point it maybe worth looking at +the <a href=../FUNCTIONS/malloc.html>malloc</a> function. + +<p> +<a name=void> +<hr> +<h2>Void Pointers</h2> + +There are times when you write a function but do not know the datatype +of the returned value. When this is the case, you can use a void pointer. +<p> + +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + int func(void *Ptr); + + main() + { + char *Str = "abc"; + + func(Str); + } + + int func(void *Ptr) + { + printf("%s\n", Ptr); + } +</pre> +</td> +</tr> +</table> +<p> + +<b>Please note, you cant do pointer arithmatic on void pointers.</b> +<p> + +<a name=ptrs> +<hr> +<h2>Pointers to pointers</h2> + +So far we have looked at pointers to data, but there is no reason why +we should not define a pointer to a pointer. The syntax looks like this. +<p> + +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + + main() + { + char **DoublePtr; + } +</pre> +</td> +</tr> +</table> +<p> + +A common use for these is when you want to return a +pointer in a function parameter. +<p> + +<table border=2 width=100% bgcolor=ivory> +<tr> +<td> +<pre> + #include <stdlib.h> /* malloc */ + + void Func(char **DoublePtr); + + main() + { + char *Ptr; + + Func(&Ptr); + } + + void Func(char **DoublePtr) + { + *DoublePtr = <a href=../FUNCTIONS/malloc.html>malloc</a>(50); + } +</pre> +</td> +</tr> +</table> +<p> + +<p> +<a name=functions> +<hr> + +<h2>Pointers to functions</h2> + +Pointers to functions can be used to create 'callback' functions. +An example of these pointers can be seen in the +<a href=../FUNCTIONS/qsort.html>qsort</a> function. +<p> +<h3>Examples.</h3> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/funcpt1.c">Simple example passing a function pointer.</a><p> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/funcpt2.c"> Example passing 'int' variables.</a><p> + +<img src="../../GRAPHICS/computer.gif"> +<a href="../EXAMPLES/funcpt3.c"> Example passing 'char' and 'char *' variables.</a><p> + +<hr> +<h2>See Also:</h2> + +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../SYNTAX/void.html">VOID keyword.</a> +<p> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../SYNTAX/functions.html">function</a> arguments. +<p> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../MISC/linklists.html">linked lists</a>. +<p> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="string.html">Strings</a>. +<p> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="arrays.html">Arrays.</a> + +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width="25%"> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> diff --git a/reference/C/CONCEPT/precedence.html b/reference/C/CONCEPT/precedence.html new file mode 100644 index 0000000..71c7d81 --- /dev/null +++ b/reference/C/CONCEPT/precedence.html @@ -0,0 +1,376 @@ +<title>Operator Precedence</title> +<head> + +</head> + +<body bgcolor="#ffffcc"> +<hr> +<center><h1>Operator Precedence</h1></center> +<hr> + + +The following tables show the order in which operators are evaluated. +Please note the following. + +<ul> +<li>The order in which the operands are evaluated is not specified in +the ANSII standard. + +<li>For readability you should not rely on these rules! Put everything +in brackets so you intension is clear to the compiler and other +programmers. +</ul> + +<dl compact> + +<dt><img src="../../GRAPHICS/whiteball.gif" width=26 height=14 alt="o" name="summary"> +<a href="#summary">Summary table.</a> + +<dt><img src="../../GRAPHICS/whiteball.gif" width=26 height=14 alt="o" name="detail"> +<a href="#detail">Table in detail.</a> + +<dt><img src="../../GRAPHICS/whiteball.gif" width=26 height=14 alt="o" name="ops"> +<a href="expressions.html">Operators listed by type.</a> +</dl> + +<hr> + +<a name=summary> +<h2>Summary precedence table.</h2> + +All operators on the same line have the same precedence. +The first line has the highest precedence. +<p> +<center> +<table border=1 center=4 bgcolor=ivory bgcolor=ivory> + +<tr align=center><td> () </td><td> [] </td><td> -> </td><td> . </td></tr> +<tr align=center><td> ! </td><td> ~ </td><td> ++ </td><td> -- </td><td> + </td> + <td> - </td><td> * </td><td> & </td><td> sizeof </td> </tr> +<tr align=center><td> * </td><td> / </td><td> % </td></tr> +<tr align=center><td> + </td><td> - </td></tr> +<tr align=center><td> << </td><td> >> </td></tr> +<tr align=center><td> < </td><td> <= </td><td> >= </td><td> > </td></tr> +<tr align=center><td> == </td><td> != </td></tr> +<tr align=center><td> & </td></tr> +<tr align=center><td> ^ </td></tr> +<tr align=center><td> | </td></tr> +<tr align=center><td> && </td></tr> +<tr align=center><td> || </td></tr> +<tr align=center><td> ?: </td></tr> +<tr align=center><td> = </td><td> += </td><td> -= </td><td> *= </td><td> /= </td> + <td> %= </td><td> &= </td><td> ^= </td><td> |= </td><td> <<= </td> + <td> >>= </td></tr> +<tr align=center><td> , </td></tr> +</table> +</center> +<p> +<i> +Lary Huang has told me that the </i><b>postfix unary --</b><i> and +</i><b>postfix unary ++</b><i> have a +higher precedence than the </i><b>prefix unary --</b><i> and +</i><b>prefix unary ++</b><i>. +</i> +<hr> + +<a name=detail> +<h2>Detailed precedence table.</h2> + +All operators in the same 'block' have the same precedence. The first block +has the +highest precedence. +<p> + +<center> +<table border=1 bgcolor=ivory> +<th>Group</th><th>Operator</th><th>Description</th><th>Example</th> +<tr> +<td> +Membership. +</td> +</tr> + +<tr align=center> +<td></td><td>()</td><td><a href="../SYNTAX/functions.html">Function call.</a></td><td>count = function(4,3);</td> +</tr> + +<tr align=center> +<td></td><td>[]</td><td><a href="arrays.html">Array.</a></td><td>value = array[5] + increment;</td> +</tr> + +<tr align=center> +<td></td><td>-></td><td><a href="../SYNTAX/struct.html#pointers">Structure pointer.</a></td> +</tr> + +<tr align=center> +<td></td><td> .</td><td><a href="../SYNTAX/struct.html#membership">Structure member.</a></td> +</tr> + +<tr align=center> +<td> +Unary. +</td> +</tr> + +<tr align=center> +<td></td><td>!</td><td><a href="../SYNTAX/logical.html#NOT">Logical NOT</a></td> +</tr> + +<tr align=center> +<td></td><td>~ </td><td> </td> +</tr> + +<tr align=center> +<td></td><td>++</td><td><a href="inc_dec.html">Increment.</a></td> +</tr> + +<tr align=center> +<td></td><td>--</td><td><a href="inc_dec.html">Decrement.</a></td> +</tr> + +<tr align=center> +<td></td><td>+ </td><td></td> +</tr> + +<tr align=center> +<td></td><td>- </td> +</tr> + +<tr align=center> +<td></td><td>*</td><td><a href="../EXAMPLES/address.c">Pointer to data</a></td> +</tr> + +<tr align=center> +<td></td><td>&</td><td><a href="../EXAMPLES/address.c">Address of a variable.</a></td> +</tr> + +<tr align=center> +<td></td><td>sizeof</td> +</tr> + +<tr align=center> +<td></td><td>(type)</td><td><a href="cast.html">type cast.</a></td> +</tr> + +<tr align=center> +<td> +Binary. +</td> + +<tr align=center> +<td></td><td>* </td><td>Multiply.</td> +</tr> + +<tr align=center> +<td></td><td>/ </td><td>Divide.</td> +</tr> + +<tr align=center> +<td></td><td>% </td><td><a href="../EXAMPLES/modulo.c">Modulo.</a></td> +</tr> + +<tr align=center> +<td> +Binary. +</td> +</tr> + +<tr align=center> +<td></td><td>+ </td><td>Addition</td> +</tr> + +<tr align=center> +<td></td><td>- </td><td>Subtraction.</td> +</tr> + +<tr align=center> +<td> +Bitwise +</td> +</tr> + +<tr align=center> +<td></td><td><< </td><td><a href="bit_shift.html">Shift left.</a></td> +</tr> + +<tr align=center> +<td></td><td>>> </td><td><a href="bit_shift.html">Shift Right.</a></td> +</tr> + +<tr align=center> +<td> +Relational. +</td> +</tr> + +<tr align=center> +<td></td><td>< </td><td>Less than.</td> +</tr> + +<tr align=center> +<td></td><td>> </td><td>Greater than.</td> +</tr> + +<tr align=center> +<td></td><td><= </td><td>Less than or equal too.</td> +</tr> + +<tr align=center> +<td></td><td>>= </td><td>Greater than or equal too.</td> +</tr> + +<tr align=center> +<td></td><td>== </td><td>Equal too.</td> +</tr> + +<tr align=center> +<td></td><td>!= </td><td>Not equal too.</td> +</tr> + +<tr align=center> +<td> +More Bitwise +</td> +</tr> + +<tr align=center> +<td></td><td>& </td><td><a href="../CONCEPT/bitwise.html">bitwise AND</a></td> +</tr> + +<tr align=center> +<td></td><td>^ </td><td><a href="../CONCEPT/bitwise.html">bitwise Excusive OR</a></td> +</tr> + +<tr align=center> +<td></td><td>| </td><td><a href="../CONCEPT/bitwise.html">bitwise OR</a></td> +</tr> + +<tr align=center> +<td> +Logical. +</td> +</tr> + +<tr align=center> +<td></td><td>&& </td><td><a href="../SYNTAX/logical.html#AND">Logical AND</a></td> +</tr> + +<tr align=center> +<td> +Logical. +</td> +</tr> + +<tr align=center> +<td></td><td>|| </td><td><a href="../SYNTAX/logical.html#OR">Logical OR</a></td> +</tr> +<tr align=center> +<td> +Conditional +</td> +</tr> + +<tr align=center> +<td></td><td>? : </td><td><a href="../SYNTAX/conditional.html">Conditional construct.</a></td> +</tr> + +<tr align=center> +<td> +Assignment +</td> +</tr> + +<tr align=center> +<td></td><td>= </td><td><a href="assignment.html">Equals</a></td> +</tr> + +<tr align=center> +<td></td><td>+= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>-= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>*= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>/= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>%= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>&= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>^= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>|= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td><<= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td></td><td>>>= </td><td><a href="assignment.html">assignment</a></td> +</tr> + +<tr align=center> +<td> +Series +</td> +</tr> + +<tr align=center> +<td></td><td>, </td><td><a href="../SYNTAX/comma.html">Comma</a></td> +</tr> +</table> +</center> + +<p> +<hr> +<h2>See also:</h2> + +<img src="../../GRAPHICS/whiteball.gif" width=26 height=14 alt="o" name="exp"> +<a href="expressions.html#bit">Expressions and operators.</a> +<br> +<img src="../../GRAPHICS/whiteball.gif" width=26 height=14 alt="o" name="ass"> +<a href="../CONCEPT/assignment.html">Assignment Operators.</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="../SYNTAX/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/CONCEPT/rpc.html b/reference/C/CONCEPT/rpc.html new file mode 100644 index 0000000..e45041c --- /dev/null +++ b/reference/C/CONCEPT/rpc.html @@ -0,0 +1,356 @@ +<title>RPC</title> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>Remote Procedure Calls (RPC).</h1></center> +<hr> +In the normal scope of things, a program can only call a function +that is linked into the executable or provided by a shared library. +RPC allows programs to execute functions in another executing program, cool! +<p> +RPC has a concept of clients and servers. +<ol> +<li>The client issues requests to the server. +<li>Servers perform the requests and return the results. +<li>The data that flows between client and server includes +int, float, strings and structures. +<li>The client and server can be on the same host or different hosts +connected via a network. +<li>The hosts do not have to be the same artitechture. +</ol> + +The RPC <a href=../glossary.html#api>API</a> has three levels of support. +By using the highest level +RPC is responcable for most of the code but is not too flexable. The lowest +level requres more coding but gives the programmer more control over how RPC +functions. +<p> +The easiest way to start with RPC is to use a program called <b>rpcgen</b> +this reads a file that describes the required interface between client and server +and generates C code that you can include in your client and server. + +<pre> + + prog.x --> rpcgen ---> prog.h Header file + ---> prog_clnt.c Client stubs file + ---> prog_svc.c Server stubs file + ---> prog_xdr.c XDR routines (more later). + +</pre> +You write <b>prog.x</b> and rpcgen generates +<b>prog.h prog_clnt.c prog_svc.c prog_xdr.c</b> + +You then write the client and server and link them with the rpcgen code +to complete the RPC system. + +<pre> + + client.c -----> client executable + prog.h ---| + prog_clnt.c ---| + prog_xdr.c ---| + + server.c -----> Server executable + prog.h ---| + prog_svc.c ---| + prog_xdr.c ---| + + +</pre> + +Ok, time for some examples. + +<h3>Calling an RPC server function without passing any arguments.</h3> +This is the simplest form of RPC. + +<p> +<center> +<table bgcolor=ivory width=80%> +<th> +void.x +</th> +<tr> +<td> +<pre> + + /* RPCGEN code decribing the client/server API. */ + + program MJLPROG + { + version MJLVERS + { + void VOID(void) = 1; + + } = 1; + } = 0x20000001; +</pre> +</td> +</tr> +</table> +</center> +<p> + +<b>void.x</b> describes the RPC interface between the client +and server. There are some important items to note here. +<p> +<table><tr> +<td bgcolor=silver> +<pre> +program MJLPROG +{ +} = 0x20000001; +</pre></td> +<td>This is the RPC program number. It is used by the client to +identify the server it intends to use. +It is important that you provide a unique number here. You can see +which values are in use with the Unix command <b>rpcinfo -p</b> or +by looking at <b>/etc/rpc</b>. Please note that the number is supplied +in void.x as a hex value but shown as a decimal value by <b>rpcinfo</b> +One other point, you should only use values in the range 0x20000000 +0x3FFFFFFF as these have been reserved for use local use. +</td> +</tr> +<tr> +<td bgcolor=silver> +<pre> +version MJLVERS +{ +} = 1; +</pre></td> +<td>The RPC Version number.</td> +</tr> +<tr> +<td bgcolor=silver><pre>void VOID(void) = 1;</pre></td> +<td>This defines the only RPC function that the server will provide.</td> +</tr> +</table> +<p> + +<center> +<table bgcolor=ivory width=80%> +<th> +void_client.c +</th> +<tr> +<td> +<pre> + + #include <rpc/rpc.h> + #include "void.h" + + main() + { + CLIENT *pclnt; + void *pVoid; + + char Host[256]; + + /* Get the name of the host running the server. */ + + gethostname(Host, 256); + + /* Connect to the server. */ + + pclnt = clnt_create(Host, MJLPROG, MJLVERS, "udp"); + + /* Issue a request to the server. */ + + void_1(pVoid, pclnt); + + /* Disconnect from the server. */ + + clnt_destroy(pclnt); + + } +</pre> +</td> +</tr> +</table> +</center> + +<p> +<table> +<tr> +<td bgcolor=silver> +<pre> +#include <rpc/rpc.h> + +</pre> +</td> +<td> +Include the standard RPC headers. +</td> +</tr> +<tr> +<td bgcolor=silver> +<pre> +#include "void.h" +</pre> +</td> +<td> +Include the header file generated by <b>rpcgen</b> +</td> +</tr> +<tr> +<td bgcolor=silver> +<pre> +pclnt = clnt_create(); +</pre> +</td> +<td>Connect to the server <b>MJLPROG</b> on <b>Host</b> and return a +pointer to the <b>CLIENT</b> control structure. +</td> +</tr> +<tr> +<td bgcolor=silver> +<pre> +void_1(pVoid, pclnt); +</pre> +</td> +<td> +Call the remote function. +</td> +</tr> +<tr> +<td bgcolor=silver> +<pre> +clnt_destroy(); +</pre> +</td> +<td> +Disconnect from the server. +</td> +</tr> +</table> +<p> + +<center> +<table bgcolor=ivory width=80%> +<th> +void_server.c +</th> +<tr> +<td> +<pre> + + #include <rpc/rpc.h> + #include "void.h" + + void *void_1_svc(void *pVoid, struct svc_req *X) + { + printf("Function called without passing arguments\n"); + } + +</pre> +</td> +</tr> +</table> +</center> + +<p> +<table> +<tr> +<td bgcolor=silver> +<pre> +void *void_1_svc() +</pre> +</td> +<td> +The server function that will be run for the client. +</td> +</tr> +</table> +<p> + +Please note that the server does not have a <b>main()</b>, rpcgen +generates it for you. +<p> +The code can be compiled with the following commands + +<pre> + gcc void_server.c void_svc.c -o void_server + gcc void_client.c void_clnt.c -o void_client +</pre> +<p> +In theory you should be able to start the server and it will +respond everytime the client is executed. I have not included any +error recovery into this example as it makes the code harder to +read. As an exercise try adding the error recovery code yourself :-) + +<h3>Transfer integers between the client and server</h3> + + +<p> +<center> +<table bgcolor=ivory width=80%> +<th> +integer.x +</th> +<tr> +<td> +<pre> + + /* RPCGEN code decribing the client/server API. */ + + program MJLPROG + { + version MJLVERS + { + int INTEGER(int) = 1; + + } = 1; + } = 0x20000001; +</pre> +</td> +</tr> +</table> +</center> + +<p> +<table> +<tr> +<td bgcolor=silver> +<pre> +int INTEGER(int) = 1; +</pre> +</td> +<td> +Server function now accepts an integer and returns an integer. +</td> +</tr> +</table> + + + + +<p> + +<hr> +<h2>See Also:</h2> + +<img src=../../GRAPHICS/whiteball.gif> +<a href=../SYNTAX/void.html>VOID keyword.</a> +<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=../SYNTAX/keywords.html>Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +29-Dec-97 +<address>Martin Leslie + + + diff --git a/reference/C/CONCEPT/storage_class.html b/reference/C/CONCEPT/storage_class.html new file mode 100644 index 0000000..884728e --- /dev/null +++ b/reference/C/CONCEPT/storage_class.html @@ -0,0 +1,219 @@ +<title>C Storage Classes</title> +<head> +</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> + +<a href="../SYNTAX/static.htm">Click here for static functions</a> +<p> +<b>static</b> is the default storage class for +<a href="../SYNTAX/glo_int_vars.html#global">global variables</a>. The two +variables below (<b>count</b> and <b>road</b>) both have a static storage class. +<p> +<center> +<table border=2 bgcolor=ivory width="50%"> +<tr> +<td> +<pre> + + static int Count; + int Road; + + main() + { + printf("%d\n", Count); + printf("%d\n", Road); + } +</pre> +</td> +</tr> +</table> +</center> +<p> + +'static' can also be defined within a function. If this is done, the variable +is initalised at compilation time and retains its value between calls. +Because it is initialsed at compilation time, the initalistation value +must be a constant. +This is serious stuff - tread with care. +<p> +<center> +<table border=2 bgcolor=ivory width="50%"> +<tr> +<td> +<pre> + + void Func(void) + { + static Count=1; + } +</pre> +</td> +</tr> +</table> +</center> +<p> +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. +<p> +<center> +<table border=2 bgcolor=ivory width="50%"> +<tr> +<td> +<pre> + + char *Func(void); + + main() + { + char *Text1; + Text1 = Func(); + } + + char *Func(void) + { + char Text2[10]="martin"; + return(Text2); + } +</pre> +</td> +</tr> +</table> +</center> +<p> +'Func' returns a pointer to the memory location where 'Text2' starts +BUT Text2 has a storage class of <a href="#auto">auto</a> and will disappear +when we exit the function and could be overwritten by something else. The +answer is to specify: +<p> +<center> +<table border=2 bgcolor=ivory width="50%"> +<tr> +<td> +<pre> + + static char Text[10]="martin"; +</pre> +</td> +</tr> +</table> +</center> +<p> +The storage assigned to 'Text2' will remain reserved for the duration if the +program. + +<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. +<pre> + + + Source 1 Source 2 + -------- -------- + + + extern int count; int count=5; + + write() main() + { { + printf("count is %d\n", count); write(); + } } +</pre> + +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> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="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="../SYNTAX/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/CONCEPT/string.html b/reference/C/CONCEPT/string.html new file mode 100644 index 0000000..532f9d7 --- /dev/null +++ b/reference/C/CONCEPT/string.html @@ -0,0 +1,157 @@ +<title>Strings</title> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>Strings.</h1></center> +<hr> +<p> +<h2>Pointers to strings.</h2> + +C does not have a "string" <a href=data_types.html>datatype</a>. +To create a string you have to use a <a href=arrays.html#char>char array</a> +or a <a href=data_types.html#char>char</a> pointer. +If you are not familur with <a href=arrays.html#char>char arrays</a> +I recomend that you read about them now. +<p> +To recap, a <a href=data_types.html#char>char</a> pointer is +<a href=../glossary.html#definitions>defined</A> like this: +<p> +<table border=2 width=100% bgcolor=ivory> +<tr><td> +<pre> + + main() + { + char *Text; + } + +</pre> +</td></tr> +</table> +<p> + +All this program does is reserve storage that will hold an address. +At this point the address could be anything. To initalize <b>Text</b> +you can code: +<p> +<table border=2 width=100% bgcolor=ivory> +<tr><td> +<pre> + + main() + { + char *Text = "Thunder"; + } + +</td></tr></table> +</pre> + +<b>Text</b> now has the address of the first character in <b>Thunder</B>. +Graphically, things look like this. + +<pre> + + (Address) (Data) + + ---- ---- + | F1 | 00 <------- Text + |----|----| (Data) (Adress) + | F2 | 00 | ------------- + |----|----| -------> 54 (T) | D1 | + | F3 | 00 | | |--------|----| + |----|----| *Text | | 68 (h) | D2 | + | F4 | D1 | ------- |--------|----| + --------- | 75 (u) | D3 | + |--------|----| + | 6E (n) | D4 | + |--------|----| + | 64 (d) | D5 | + |--------|----| + | 65 (e) | D6 | + |--------|----| + | 72 (r) | D7 | + |--------|----| + | 00 | D8 | + ------------- + +</pre> +<p> + +Please note the <b>00</b> at the end of <b>Thunder</b>. This is +the <a href=../SYNTAX/null.html>NULL</a> character and is used to mark the +end of a string. +<p> +If we wanted to O/P the data pointed to by a <b>char pointer</b> + we can code. +<p> +<table border=2 width=100% bgcolor=ivory> +<tr align=center><td> +<b>Source</b> +</td></tr><tr><td> +<pre> + + main() + { + char *Text1 = "Thunder"; /* Define and initalize */ + char *Text2; /* Define only */ + + Text2 = "Bird"; /* Point to some text */ + + <a href=../FUNCTIONS/printf.html>printf</a>("%s%s\n", Text1, Text2); + } + +</pre> +</td></tr> +<tr align=center><td> +<b>Result</b> +</td></tr><tr><td> +<pre> + + ThunderBird + +</pre> +</td></tr></table> +<p> + +This is all very well, but there is a MAJOR problem! <b>Thunder</b> +and <b>Bird</b> are +<a href=constants.html>constants</a>, they cannot be +changed in anyway. +We need a method of pointing to some storage that can be altered +and true to form, C provides a function called +<a href=../FUNCTIONS/malloc.html>malloc</a> to do just that. +<p> + +<hr> +<h2>See Also:</h2> + +<img src=../../GRAPHICS/whiteball.gif> +<a href=../SYNTAX/void.html>VOID keyword.</a> +<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=../SYNTAX/keywords.html>Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> + + diff --git a/reference/C/CONCEPT/true_false.html b/reference/C/CONCEPT/true_false.html new file mode 100644 index 0000000..db7f90e --- /dev/null +++ b/reference/C/CONCEPT/true_false.html @@ -0,0 +1,78 @@ +<title>True or False</title> +<body bgcolor="#ffffcc"> +<hr> +<center> +<h1>True or False.</h1> +</center> +<hr> +The concept of an <a href="../CONCEPT/expressions.html">expression</a> evaluating to true or false is one of +the corner stones of C. BUT the language derives true and false in an +unusual way.<p> +Basicly there is no boolean value. The number 0 is considered to be false +and all other numbers are considered to be true....<p> + +Please consider the following expressions. + +<pre> + (1 == 1) true + (1 != 1) false + (i = 1) true + (i = 0) false + (i = 1 + 1) true +</pre> +The first two examples should be clear but the last ones need explanation .<p> +The last three examples assign a value to a variable and a side effect of +assignment is to return the value assigned, it is <b>this</b> value that is tested +to be true or false.<p> +Looking at the last example: +<pre> + (i = 1 + 1) + (i = 2) + (2) +</pre> + +<ul> +<li>The third expression assigns a value of 1 to <b>i</b>. 1 is considered to +be true because it is non-zero. +<p> +<li>The fourth expression assigns a value of 0 to <b>i</b>. 0 is considered to +be false. +<p> +<li>The fith expression assigns a value of 2 to <b>i</b>. 2 is considered to +be true, because it is non-zero. +</ul> +<p> +<hr> +<h2>See Also:</h2> +<img src=../../GRAPHICS/whiteball.gif> +<A HREF="../SYNTAX/enum.html">enum keyword</A> +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> Corrections made by Christopher Wolf +<! cwolf@tools.micro.ti.com> + + diff --git a/reference/C/CONCEPT/type_conv.html b/reference/C/CONCEPT/type_conv.html new file mode 100644 index 0000000..485f325 --- /dev/null +++ b/reference/C/CONCEPT/type_conv.html @@ -0,0 +1,63 @@ +<title>Data type conversion</title> +<body bgcolor="#ffffcc"> +<hr> +<center><h1>Data type conversion</h1></center> +<hr> + +An <a href="../CONCEPT/expressions.html">operator</a> must have +<a href="../glossary.html#operand">operands</a> +of the same +type before it can carry out the operation. Because of this, C will perform +some automatic conversion of <a href="data_types.html">data types</a>. +<p> +These are the general rules for binary operators (* + / % etc): +<p> +<ul> +<li>If either operand is <b>long double</b> the other is converted to +<b>long double</b>. +<p> +<li>Otherwise, if either operand is <b>double</b> the other is converted +to <b>double</b> +<p> +<li>Otherwise, if either operand is <b>float</b> the other is converted +to <b>float</b> +<p> +<li>Otherwise, convert <b>char</b> and <b>short</b> to <b>int</b> +<p> +<li>Then, if an operand is <b>long</b> convert the other to <b>long</b>. +</ul> + +<hr> +<h2>See Also</h2> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../CONCEPT/cast.html">cast</a> to force a type conversion. +<br> +<img src="../../GRAPHICS/whiteball.gif"> +<a href="../SYNTAX/typedef.html">typedef</a> keyword. +<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="../SYNTAX/keywords.html">Keywords</a> +</td><td width=25%> +<a href="../FUNCTIONS/funcref.htm">Functions</a> +</td> +</tr> +</table> +</center> +<p> + +<hr> +<address>Martin Leslie +<script language="JavaScript"> +<!-- // +document.write(document.lastModified); +// --> +</script> +</address> |