From 7e0f021a9aec35fd8e6725e87e3313b101d26f5e Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Sun, 27 Jan 2008 11:37:44 +0100 Subject: Initial import (2.0.2-6) --- reference/C/CONCEPT/JavaSim.html | 254 +++++++++++++++ reference/C/CONCEPT/Makefile.am | 5 + reference/C/CONCEPT/Makefile.in | 410 ++++++++++++++++++++++++ reference/C/CONCEPT/arrays.html | 212 +++++++++++++ reference/C/CONCEPT/assignment.html | 91 ++++++ reference/C/CONCEPT/bit_shift.html | 219 +++++++++++++ reference/C/CONCEPT/bitsnbytes.html | 84 +++++ reference/C/CONCEPT/bitwise.html | 231 ++++++++++++++ reference/C/CONCEPT/cast.html | 75 +++++ reference/C/CONCEPT/cmdline.html | 48 +++ reference/C/CONCEPT/constants.html | 143 +++++++++ reference/C/CONCEPT/data_types.html | 218 +++++++++++++ reference/C/CONCEPT/expressions.html | 135 ++++++++ reference/C/CONCEPT/inc_dec.html | 84 +++++ reference/C/CONCEPT/pointers.html | 559 +++++++++++++++++++++++++++++++++ reference/C/CONCEPT/precedence.html | 376 ++++++++++++++++++++++ reference/C/CONCEPT/rpc.html | 356 +++++++++++++++++++++ reference/C/CONCEPT/storage_class.html | 219 +++++++++++++ reference/C/CONCEPT/string.html | 157 +++++++++ reference/C/CONCEPT/true_false.html | 78 +++++ reference/C/CONCEPT/type_conv.html | 63 ++++ 21 files changed, 4017 insertions(+) create mode 100644 reference/C/CONCEPT/JavaSim.html create mode 100644 reference/C/CONCEPT/Makefile.am create mode 100644 reference/C/CONCEPT/Makefile.in create mode 100644 reference/C/CONCEPT/arrays.html create mode 100644 reference/C/CONCEPT/assignment.html create mode 100644 reference/C/CONCEPT/bit_shift.html create mode 100644 reference/C/CONCEPT/bitsnbytes.html create mode 100644 reference/C/CONCEPT/bitwise.html create mode 100644 reference/C/CONCEPT/cast.html create mode 100644 reference/C/CONCEPT/cmdline.html create mode 100644 reference/C/CONCEPT/constants.html create mode 100644 reference/C/CONCEPT/data_types.html create mode 100644 reference/C/CONCEPT/expressions.html create mode 100644 reference/C/CONCEPT/inc_dec.html create mode 100644 reference/C/CONCEPT/pointers.html create mode 100644 reference/C/CONCEPT/precedence.html create mode 100644 reference/C/CONCEPT/rpc.html create mode 100644 reference/C/CONCEPT/storage_class.html create mode 100644 reference/C/CONCEPT/string.html create mode 100644 reference/C/CONCEPT/true_false.html create mode 100644 reference/C/CONCEPT/type_conv.html (limited to 'reference/C/CONCEPT') 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 @@ +Bit Manipulation Simulator + + + + + + +
+
+

Bit Manipulation Simulator

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

+ +


+

+

+
+Enter the Hex values and select an operator, then press the 'Execute' +button to see the results. +

+ + + + + + + +

+
+ +
+ + + + + + + + + + + + + + + +
HexBinaryDecimal
+

+ +

+
+

+ +

+
+

+ +

+
+
+

+ + +Sections of this page controlled by 'JavaScript' cannot be printed. + +

+


+

See Also:

+ +Bitwise Operators. +

+


+

+

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

+


+
Martin Leslie + +
+- 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 @@ +Arrays + +
+
+

Arrays.

+
+
+Arrays can be created from any of the C data types +int, +float, +char. I start with int and +float +as these are the easiest to understand. Then move onto int +and float +multi dimentional arrays and finally char arrays + + + +
+

int and float arrays

+To
define an integer or +floating point variable you would say. +
+	main()
+	{
+	  int   Count;		/* integer variable 		*/
+	  float Miles;		/* floating point variable	*/
+	}
+
+The syntax for an array is: +
+	main()
+	{
+	  int   Count[5];	/* 5 element integer array	*/
+	  float Miles[10];	/* 10 element floating point array */
+	}
+
+ +Now, the important fact is that the elements start at 0 (ZERO), so, +'Count' above has elements 0, 1, 2, 3, 4.

+To change the value of the 5th element we would code: +

+	main()
+	{
+	  int Count[5];
+	  Count[4] = 20;	/* code 4 to update the 5th element */
+	}
+
+ +If we want to initalise 'Count' at definition we can say: +
+	main()
+	{
+	  int i;
+	  int Count[5]={10, 20, 30};
+	  for (i=0; i< 5; i++)
+      	  {
+   	    printf("%d ", Count[i]);
+   	  }
+	  puts("");
+	}
+
+ +The result will be: +
+	10 20 30 0 0 
+
+We can see from the example above that the elements that have NOT been +initalised +have been set to zero.

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

+	main()
+	{
+	  int i;
+	  int Count[]={10, 20, 30};
+	}
+
+ +Don't forget, all the stuff so far also applies to float. +

+ + +


+

Two dimensional int and float arrays.

+ +C does not actually support multi-dimensional arrays, but you can +emulate them. +
+	main()
+	{
+	  int Count[5];
+	  int Matrix[10][4];
+	}
+
+Count has been seen before, it defines an array of 5 elements.

+Matrix is defined as 10 arrays, all with 4 elements.

+To initalise Matrix at definition, you would code the following. +

+	main()
+	{
+	  int Matrix[4][2]={{1, 2},
+	  		    {3, 4},
+			    {5, 6},
+			    {7, 8}};
+	}
+
+Dont forget the last element will be Matrix[3][1] +

+ + +


+

char arrays.

+ +char arrays work in the same way as int and float +
+	main()
+	{
+	  char Letter;
+	  char Letters[10];
+	}
+
+'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.

+To initalise 'char' variables you can use the following syntax. +

+	main()
+	{
+	  char Letter='x';
+	  char Letters[10]='f','a','x',' ','m','o','d','e','m','\0';
+	  char Text[10]="fax modem";
+	}
+
+Note that the double quotes mean 'text string' and so they will add the +
NULL +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 strcpy. +

+ + +


+

Two dimensional char arrays.

+ +Two dimensional arrays are a different kettle of fish! We can follow the +rules above to define the array like this. +
+	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' */
+	}
+
+ +The example above has reserved 18 consecutive bytes and created three +pointers into them. +
+
+                  ---------------------
+                 |red  \0green\0blue \0|
+                  ---------------------
+                  A      A      A
+                  |      |      |
+   Colours[0] ----       |      |
+   Colours[1] -----------       |
+   Colours[2] ------------------
+
+
+
+

+ +click here for chat on pointers. + +

+

+


+

+

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

+ +


+
Martin Leslie + +
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 @@ +Assignment operators. + +
+
+

Assignment operators.

+
+
+ +C has the following assignement operators: +
+	=   +=   -=   *=   /=   %=   <<=   >>=   &=   ^=   |=
+
+= is the obvious one. It takes the result of the expression on the right +and assigns it to the variable on the left (lvalue). +
+	main ()
+        {
+	  int a, b=4, c=10;
+	  a = b + c;
+	}
+
+I know this is stating the obvious, but: +
    +
  1. b is assigned the value 4 +
  2. c is assigned the value 10 +
  3. a is assigned the result of b plus C (14). +
+ +
+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. +
+	main ()				main()
+	{				{
+	  int a=4;			  int a=4;
+	  a = a * 4;			  a *= 4;
+	}				}
+
+The rule is as follows: +

+The lvalue is multiplied by the rvalue and the result assigned to the +lvalue. +

+Here is another example. +

+	main()				main()
+	{				{
+	    int a=10, b=2;	            int a=10, b=2;
+	    a /= b * 5;		            a = a / (b*5);
+	}				}
+
+Again both preduce the same answer (1). +

+


+ + +Increment (++) and Decrement (--)
+ + +Bit shifting ( >>= <<= )
+ + +Operator precedence table. +
+

+

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

+ +


+
Martin Leslie + +
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 @@ +Bitwise operations + +
+
+

Bitwise operations

+
+
+ +

+Bitwise operators include: +

+

+ + + + + + + + + + + +
& AND
&= AND
| OR
|= OR
^ XOR
~ one's compliment
<< Shift Left
>> Shift Right
<<= Shift Left
>>=Shift Right
+
+

+ + +


+

AND OR and XOR

+ +These require two operands and will perform bit comparisions. +

+AND & +will copy a bit to the result if it exists in both operands. +

+

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

+OR | will copy a bit if it exists in eather operand. +

+

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

+XOR ^ copies the bit if it is set in one operand (but not both). +

+

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

+ +


+

Ones Complement

+ +This operator is unary (requires one operand) and has the efect of +'flipping' bits. +

+

+ + +
+
+
+  main()
+  {
+    unsigned int Value=4;          /*   4 = 0000 0100 */  
+
+    Value = ~ Value;               /* 251 = 1111 1011 */  
+
+  }
+
+
+
+
+

+ + +

+ +


+

Bit shift.

+The following
operators +can be used for shifting bits left or right. +

+

+ + + + + + + +
<< >> <<= >>=
+
+

+The left operands value is moved left or right by the number of bits specified +by the right operand. For example: +

+

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

+Usually, the resulting 'empty' +bit is assigned ZERO. +Please use +unsigned +variables with these operators to avoid unpredictable +results. +

+


+

Examples:

+ AND
+ OR
+ Bit shifting. +
+

Problem:

+ +Bit shifting problem. +
+

See Also:

+ +All the other Expressions and operators.
+ +Operator precedence.
+ +Assignment Operators. +
+

+

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

+


+
Martin Leslie + +
+ 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 @@ +Bits 'n Bytes + +
+
+

Bits 'n Bytes.

+
+
+ +This is basic Computer Science but its worth restating the basics +sometimes. +

+


+

bits

+ +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. +
+Off == 0
+On  == 1
+
+

+


+

Bytes

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

KiloBytes

+ +This is a thousand bytes. The exact value is 2 to the power of 10 +or 1,024 + +

MegaBytes

+This is a Million bytes. The exact value is 2 to the power of 20 +or 1,048,576 + +

GigaBytes

+ +The exact value is 2 to the power of 30 +or 1,073,741,824 + +

TeraBytes

+ +The exact value is 2 to the power of 40 +or 1,099,511,627,776 (big....) + +

+


+

+

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

+ +


+
Martin Leslie + +
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 @@ +Bitwise operations + +
+
+

Bitwise operations

+
+
+ +

+Bitwise operators include: +

+

+ + + + + + + + + + + + +
& AND
&= AND
| OR
|= OR
^ XOR
^= XOR
~ one's compliment
<< Shift Left
<< Shift Left
>>= Shift Right
>>=Shift Right
+
+

+ + +


+

AND OR and XOR

+ +These require two operands and will perform bit comparisions. +

+AND & +will copy a bit to the result if it exists in both operands. +

+

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

+OR | will copy a bit if it exists in eather operand. +

+

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

+XOR ^ copies the bit if it is set in one operand (but not both). +

+

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

+o +XOR example program which swaps the contents of two variables. + +

+ +


+

Ones Complement

+ +This operator is unary (requires one operand) and has the efect of +'flipping' bits. +

+

+ + +
+
+
+  main()
+  {
+    unsigned int Value=4;          /*   4 = 0000 0100 */  
+
+    Value = ~ Value;               /* 251 = 1111 1011 */  
+
+  }
+
+
+
+
+ +

+ +


+

Bit shift.

+The following
operators +can be used for shifting bits left or right. +

+

+ + + + + + + +
<< >> <<= >>=
+
+

+The left operands value is moved left or right by the number of bits specified +by the right operand. For example: +

+

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

+Usually, the resulting 'empty' +bit is assigned ZERO. +Please use +unsigned +variables with these operators to avoid unpredictable +results. +


+

Examples:

+ +AND
+ +OR
+ +Bit shifting. +
+

Problem:

+ +Bit shifting problem. +
+

See Also:

+ +All the other Expressions and operators.
+ +Operator precedence.
+ +Assignment Operators. +
+

+

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

+


+
Martin Leslie + +
+ + + + + + + + + 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 @@ + +cast + + +
+
+

To cast, casting

+
+
+ +If you want to change the +datatype of a variable +you have to use a technic called cast. For example if want to +change an int to a +float +you could use the following syntax: +

+

+ + + + +
+
+        
+    main()
+    {
+        int var1;
+        float var2;
+
+        var2 = (float)var1;
+    }
+
+
+
+

+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 () . This states, +the result of the expression (in this case var1) is to be a +data type of float. +

+


+

See Also:

+ + C++ changes to cast. +

+


+

+

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

+ +


+
Martin Leslie + +
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 @@ +Command line arguments + +
+
+

Command line arguments

+
+
+ + + +
+

Examples:

+ + Example using argc and argv +
+ + Bob Stout's example. +
+

See Also:

+ +getopt function. +
+

+

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

+ +


+
Martin Leslie + +
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 @@ +Constants + +
+

Constants

+
+Be sure you understand the difference between a 'constant' and a +declaration. +A constant has a value that cannot be changed. For example: +
+
+	1234
+	'x'
+	9.89
+	"String"
+
+
+Constants are used to assign a value to a variable. E.G +
+	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.	*/
+
+ +
+

Integer constants.

+Interger constants can be expressed in the following ways. +
+	1234	(decimal)
+	0xff	(Hexidecimal)
+	0100	(Octal)
+	'\xf'	(Hex character)
+
+Examples of their use are: +
+	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'); 
+
+
+Integer constants are assumed to have a datatype of +
int, if it will not fit into an 'int' +the compiler will assume the constant is a +long. You may also force the +compiler to use 'long' by putting an 'L' on the end of the +integer constant. +
+        1234L           /* Long int constant (4 bytes)          */
+
+The other modifier is 'U' for Unsigned. +
+        1234U           /* Unsigned int                         */
+
+and to complete the picture you can specify 'UL' +
+        1234UL          /* Unsigned long int                    */
+
+ +
+

Floating point constants.

+Floating point constants contain a decimal point or exponent. By default +they are double. +
+	123.4
+	1e-2
+
+	
+
+
+

Chararacter constants.

+Are actually integers. +
+	'x'
+	'\000'
+	'\xhh'
+
+	escape sequences
+
+
+ +
+ +

String constants.

+ +Strings do not have a datatype of their own. +They are actually a sequence of char items terminated with a +\0. A string can be accessed with a +char pointer. +

+An example of a string would be: +

+
+	char *Str = "String Constant";
+
+
+ +See the discussion on +strings for more information. +

+ +


+

Also see:

+ +
+

+

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

+ +


+
Martin Leslie + +
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 @@ +C Data types + +
+
+

C Data types.

+
+
+

+ +

Variable definition

+C has a concept of 'data types' which are used to +define a variable +before its use.

+The definition of a variable will assign storage for the variable and +define the type of data that will be held in the location.

+So what data types are available? +

+ + +
int +float +double +char +void +enum +
+

+Please note that there is not a boolean data type. C does not have the +traditional view about logical comparison, but thats another story.

+ +Recent C++ compilers do have a boolean datatype. +

+ +


+

int - data type

+int is used to define integer numbers. +

+

+ +
+
+
+    {
+        int Count;
+        Count = 5;
+    }
+
+
+
+

+


+

float - data type

+float is used to define floating point numbers. +

+

+ +
+
+
+    {
+        float Miles;
+        Miles = 5.6;
+    }
+
+
+
+

+


+

double - data type

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

+

+ +
+
+
+    {
+        double Atoms;
+        Atoms = 2500000;
+    }
+
+
+
+

+


+

char - data type

+char defines characters. +

+

+ +
+
+
+    {
+        char Letter;
+        Letter = 'x';
+    }
+
+
+
+

+ +


+

Modifiers

+The three data types above have the following modifiers. +

+

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

+

+

+ +
+
+
+        short int <=    int <= long int
+            float <= double <= long double
+
+
+
+

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

+ + +
+
+
+                 Type  Bytes  Bits                Range
+
+
+
+
+            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
+
+
+

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

+You can find out how much storage is allocated to a data type by using +the sizeof operator. + +


+

Qualifiers

+

+

+ +The const qualifier is used to tell C that the variable value can not +change after initialisation.

+ + const float pi=3.14159; + +

+pi cannot be changed at a later time within the program.

+Another way to define constants is with the +#define preprocessor which +has the advantage that it does not use any storage (but who counts bytes + these days?).

+


+

See also:

+Data type conversion +

+Storage classes. +

+cast +

+typedef keyword. + +


+

+

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

+ +


+
Martin Leslie + +
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 @@ + +C operators + + +
+
+

C Operators/Expressions

+
+
+

+ +Operators are used with +operands +to build expressions. For example the +following is an expression containing two operands and one oprator. + +

+        4 + 5
+
+ +The following list of operators is probably not complete but does highlight +the common +operators and a few of the outrageous ones.... +

+C contains the following operator groups. +

+The order (precedence) that operators are evaluated can be seen +here. + +

Arithmetic

+
+        +
+        -
+        /
+        *
+        %       modulo
+        --      Decrement (post and pre)
+        ++      Increment (post and pre)
+
+

Assignment

+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: +
   counter = counter + 1; 
+can be reduced to +
   counter += 1;           
+Here is the full set. +
+        =
+        *=      Multiply
+        /=      Divide.
+        %=      Modulus.
+        +=      add.
+        -=      Subtract.
+        <<=     left shift.
+        >>=     Right shift.
+        &=      Bitwise AND.
+        ^=      bitwise exclusive OR (XOR).
+        |=      bitwise inclusive OR.
+
+

Logical/Relational

+
+        ==      Equal to
+        !=      Not equal to
+        >
+        <
+        >=
+        <=
+        &&      Logical AND
+        ||      Logical OR
+        !       Logical NOT
+
+

Bitwise

+
+        &       AND (Binary operator)
+        |       inclusive OR
+        ^       exclusive OR
+        <<      shift left. C ++ use of <<
+
+        >>      shift right. C ++ use of >>
+        ~       one's complement
+
+ +

Odds and ends!

+
+        sizeof() size of objects and data types.
+                 strlen may also be of interest.
+        &       Address of (Unary operator)
+        *       pointer (Unary operator)
+        ?       Conditional expressions
+        :       Conditional expressions
+        ,       Series operator.
+
+
+

+

C++ Extensions

+ + +Read about :: >> and << in the world of C++ +here! + +
+

+

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

+ +


+
Martin Leslie + +
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 @@ +Increment and decrement. + +
+
+

Increment and decrement.

+
+
+ +The traditional method of incrementing numbers is by coding something like: +
+	a = a + 1;
+
+Within C, this syntax is valid but you can also use the ++ operator to perform +the same function. +
+	a++;
+
+will also add 1 to the value of a. +By using a simular syntax you can also decrement a variable as shown below. +
+	a--;
+
+These operators can be placed as a prefix or post fix as below: +
+	a++;		++a;
+
+When used on their own (as above) the prefix and postfix have the same effect +BUT within an expression there is a subtle difference....

+ +

    +
  1. Prefix notation will increment the variable BEFORE the +expression is evaluated. +
  2. Postfix notation will increment AFTER the expression evaluation. +
+ +Here is an example: +
+	main()				main()
+	{				{
+	  int a=1;			  int a=1;
+	  printf(" a is %d", ++a);	  printf(" a is %d", a++);
+        }				}
+
+
+ +In both examples, the final value of a will be 2. BUT the first +example will print 2 and the second will print 1. + +
+ + Example program.
+ + +Other operators.
+ + +Operator precedence table. +
+

+

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

+ +


+
Martin Leslie + +
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 @@ +Pointers + +
+

Pointers.

+
+

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

+

+ + + +
+

First Principles.

+To understand pointers, it may be worth understanding how normal +variables are stored. If you disagree,
Click here +to move on. +

+What does the following program realy mean? +

+ + + + +
+
+
+        main()
+	{
+  	    int Length;     
+	}      
+
+
+

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

+
+      (Address) (Data)
+           ---- ----
+          | F1 |   <------- Length
+          |----|----|
+          | F2 |    |       
+          |----|----|
+          | F3 |    |
+          |----|----|
+          | F4 |    |
+           ---------    
+
+
+To put a known value into 'Length' we code, +

+ + + + +
+
+
+	main()
+	{
+	    int Length;
+  	    Length = 20;
+        }
+
+
+

+the deciamal value 20 (Hex 14) is placed into the storage location. +

+
+      (Address) (Data)
+	   ---- ----
+          | F1 | 00 <------- Length
+          |----|----|
+          | F2 | 00 |
+          |----|----|
+          | F3 | 00 |
+          |----|----|
+          | F4 | 14 |
+           ---------
+     
+
+Finally, if the program is expanded to become +

+ + + + +
+
+
+      main()
+      {
+          int Length;
+
+          Length = 20;
+
+          printf("Length is %d\n", Length);
+          printf("Address of Length is %p\n", &Length);
+      }
+      
+
+
+

+The output would look something like this ..... +

+    
+      Length is 20
+      Address of Length is 0xF1
+      
+
+ +Please note the '&Length' on the second printf statement. +The & means address of Length. +If you are happy with this, you should push onto the pointers below. +

+ +


+

Pointer definition.

+ +A pointer contains an
address that points + +to data. +

+An example of code defining a pointer could be... +

+ + + + +
+
+
+      main()
+      {
+          int *Width;
+      }
+
+
+
+

+A graphical representation could be... +

+
+      (Address) (Data)
+           ---- ----
+          | F1 |    <------- Width
+          |----|----|
+          | F2 |    |
+          |----|----|
+          | F3 |    |
+          |----|----|
+          | F4 |    |
+           ---------
+		   
+
+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. +

+ + + + +
+
+
+      main()
+      {
+          int *Width;                                 /* 1 */
+
+          Width = (int *)malloc(sizeof(int));         /* 2 */
+
+          *Width = 34;                                /* 3 */
+      }
+
+
+
+

+
+      (Address) (Data)
+           ---- ----    
+          | F1 | 00 <------- Width   
+	  |----|----|               (Data) (Adress)
+          | F2 | 00 |                 ---------
+	  |----|----|         -------> 00 | D1 |
+	  | F3 | 00 |        |       |----|----|
+	  |----|----|  *Width|       | 00 | D2 |
+	  | F4 | D1 | -------        |----|----|
+	   ---------                 | 00 | D3 |
+	                             |----|----|
+				     | 22 | D4 |
+				      ---------
+		 
+
+ +Statements 2 and 3 are important here: +

+2) The malloc function reserves some storage and puts the address of the +storage into Width. +

+3) *Width puts a value into the storage pointed to by Width. +

+ +Unlike the +Length = 20 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... +

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

+The program would O/P something like. +

+ + + + +
+
+
+          Data stored at *Width is 34
+	       Address of Width is 0xF1
+	Address stored at Width is 0xD1
+
+
+
+ +

+A pointer can point to any data type, ie +int, +float, +char. +When defining a pointer you +place an * (asterisk) character +between the data type and the variable name, here are a few examples. +

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

+ + +

+ + +


+

Pointers to arrays

+When looking at +
arrays we had a program that accessed data within a +two dimensional character array. This is what the code looked like. + +
+        main()
+        {
+          char colours[3][6]={"red","green","blue"};
+        }
+
+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. +
+        main()
+        {
+          char *colours[]={"red","green","blue"};
+        }
+
+ +Graphically it looks like this: +

+ +
+
+
+
+
+                        
+     colours  *colours *(colours+2) **colours
+          |         |       |           |
+          |         |       |           |
+          V         V       V           |     
+         ---       -----------          |     
+        |   |---->|   |   |   |         |     
+         ---       -----------          |     
+                    |   |   |           V     
+                    |   |   |         -----------------------
+                     --------------->| r | e | d |   |   |   |
+                        |   |         -----------------------
+                        |   |      
+                        |   |          -----------------------
+                         ---|-------->| g | r | e | e | n |   |
+                            |          -----------------------
+                            |
+                            |          -----------------------
+                             -------->| b | l | u | e |   |   |
+                                       -----------------------
+		            	        A           A
+                                        |           |
+                                        |           |
+                                **(colours+2)   *(*(colours+2)+3)
+                                 
+
+
+

+

+	printf("%s \n", colours[1]);
+	printf("%s \n", *(colours+1))
+
+will both return green. +

+ + +


+

Char Arrays verses Char pointers

+ +What is the difference +between these two lumps of code? +

+ +
+
+	
+  main()			
+  {			
+      char colour[]="red";		
+      printf("%s \n",colour);	
+  }				
+
+
+
+
+
+  main()
+  {				
+      char *colour="red";
+      printf("%s \n",colour);	
+  }				
+
+
+
+

+The answer is, NOTHING! They both print the word +red because in both cases 'printf' is being passed a pointer to a +string. +

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

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

+ +

+At this point it maybe worth looking at +the malloc function. + +

+ +


+

Void Pointers

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

+ + + + + +
+
+
+  	int func(void *Ptr);
+
+  	main()
+  	{
+            char *Str = "abc";
+
+            func(Str);
+  	}
+
+  	int func(void *Ptr)
+  	{
+  	    printf("%s\n", Ptr);
+  	}
+
+
+

+ +Please note, you cant do pointer arithmatic on void pointers. +

+ + +


+

Pointers to pointers

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

+ + + + + +
+
+
+	main()
+	{
+	    char **DoublePtr;
+	}
+
+
+

+ +A common use for these is when you want to return a +pointer in a function parameter. +

+ + + + + +
+
+   	#include 		/* malloc */
+
+	void Func(char **DoublePtr);
+
+	main()
+	{
+            char *Ptr;
+
+	    Func(&Ptr);
+	}
+
+	void Func(char **DoublePtr)
+	{
+	    *DoublePtr = malloc(50);
+	}
+
+
+

+ +

+ +


+ +

Pointers to functions

+ +Pointers to functions can be used to create 'callback' functions. +An example of these pointers can be seen in the +
qsort function. +

+

Examples.

+ + +Simple example passing a function pointer.

+ + + Example passing 'int' variables.

+ + + Example passing 'char' and 'char *' variables.

+ +


+

See Also:

+ + +VOID keyword. +

+ +function arguments. +

+ +linked lists. +

+ +Strings. +

+ +Arrays. + +


+

+

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

+ +


+
Martin Leslie + +
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 @@ +Operator Precedence + + + + + +
+

Operator Precedence

+
+ + +The following tables show the order in which operators are evaluated. +Please note the following. + + + +
+ +
o +Summary table. + +
o +Table in detail. + +
o +Operators listed by type. +
+ +
+ + +

Summary precedence table.

+ +All operators on the same line have the same precedence. +The first line has the highest precedence. +

+

+ + + + + + + + + + + + + + + + + + + + +
() [] -> .
! ~ ++ -- + - * & sizeof
* / %
+ -
<< >>
< <= >= >
== !=
&
^
|
&&
||
?:
= += -= *= /= %= &= ^= |= <<= >>=
,
+
+

+ +Lary Huang has told me that the postfix unary -- and +postfix unary ++ have a +higher precedence than the prefix unary -- and +prefix unary ++. + +


+ +
+

Detailed precedence table.

+ +All operators in the same 'block' have the same precedence. The first block +has the +highest precedence. +

+ +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
GroupOperatorDescriptionExample
+Membership. +
()Function call.count = function(4,3);
[]Array.value = array[5] + increment;
->Structure pointer.
.Structure member.
+Unary. +
!Logical NOT
~
++Increment.
--Decrement.
+
-
*Pointer to data
&Address of a variable.
sizeof
(type)type cast.
+Binary. +
* Multiply.
/ Divide.
% Modulo.
+Binary. +
+ Addition
- Subtraction.
+Bitwise +
<< Shift left.
>> Shift Right.
+Relational. +
< Less than.
> Greater than.
<= Less than or equal too.
>= Greater than or equal too.
== Equal too.
!= Not equal too.
+More Bitwise +
& bitwise AND
^ bitwise Excusive OR
| bitwise OR
+Logical. +
&& Logical AND
+Logical. +
|| Logical OR
+Conditional +
? : Conditional construct.
+Assignment +
= Equals
+= assignment
-= assignment
*= assignment
/= assignment
%= assignment
&= assignment
^= assignment
|= assignment
<<= assignment
>>= assignment
+Series +
, Comma
+
+ +

+


+

See also:

+ +o +
Expressions and operators. +
+o +Assignment Operators. +
+ + +

+ +


+

+

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

+


+
Martin Leslie +

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


+

Remote Procedure Calls (RPC).

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

+RPC has a concept of clients and servers. +

    +
  1. The client issues requests to the server. +
  2. Servers perform the requests and return the results. +
  3. The data that flows between client and server includes +int, float, strings and structures. +
  4. The client and server can be on the same host or different hosts +connected via a network. +
  5. The hosts do not have to be the same artitechture. +
+ +The RPC API 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. +

+The easiest way to start with RPC is to use a program called rpcgen +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. + +

+
+	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).
+
+
+You write prog.x and rpcgen generates +prog.h prog_clnt.c prog_svc.c prog_xdr.c + +You then write the client and server and link them with the rpcgen code +to complete the RPC system. + +
+
+	client.c    -----> client executable
+        prog.h      ---|
+        prog_clnt.c ---|
+        prog_xdr.c  ---|
+
+        server.c    -----> Server executable
+        prog.h      ---|
+        prog_svc.c  ---|
+        prog_xdr.c  ---|
+
+
+
+ +Ok, time for some examples. + +

Calling an RPC server function without passing any arguments.

+This is the simplest form of RPC. + +

+

+ + + + + +
+void.x +
+
+
+  /* RPCGEN code decribing the client/server API. */
+ 
+  program MJLPROG
+  {
+    version MJLVERS
+    {
+      void VOID(void) = 1;
+    
+    } = 1;
+  } = 0x20000001;
+
+
+
+

+ +void.x describes the RPC interface between the client +and server. There are some important items to note here. +

+ + + + + + + + + + + + +
+
+program MJLPROG
+{
+} = 0x20000001;
+
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 rpcinfo -p or +by looking at /etc/rpc. Please note that the number is supplied +in void.x as a hex value but shown as a decimal value by rpcinfo +One other point, you should only use values in the range 0x20000000 +0x3FFFFFFF as these have been reserved for use local use. +
+
+version MJLVERS
+{
+} = 1;
+
The RPC Version number.
void VOID(void) = 1;
This defines the only RPC function that the server will provide.
+

+ +

+ + + + + +
+void_client.c +
+
+
+  #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);
+
+  }
+
+
+
+ +

+ + + + + + + + + + + + + + + + + + + + + +
+
+#include <rpc/rpc.h>
+
+
+
+Include the standard RPC headers. +
+
+#include "void.h"
+
+
+Include the header file generated by rpcgen +
+
+pclnt = clnt_create();
+
+
Connect to the server MJLPROG on Host and return a +pointer to the CLIENT control structure. +
+
+void_1(pVoid, pclnt);
+
+
+Call the remote function. +
+
+clnt_destroy();
+
+
+Disconnect from the server. +
+

+ +

+ + + + + +
+void_server.c +
+
+
+  #include 
+  #include "void.h"
+
+  void *void_1_svc(void *pVoid,  struct svc_req *X)
+  {
+      printf("Function called without passing arguments\n");
+  }
+
+
+
+
+ +

+ + + + + +
+
+void *void_1_svc()
+
+
+The server function that will be run for the client. +
+

+ +Please note that the server does not have a main(), rpcgen +generates it for you. +

+The code can be compiled with the following commands + +

+  gcc void_server.c void_svc.c -o void_server
+  gcc void_client.c void_clnt.c -o void_client
+
+

+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 :-) + +

Transfer integers between the client and server

+ + +

+

+ + + + + +
+integer.x +
+
+
+  /* RPCGEN code decribing the client/server API. */
+ 
+  program MJLPROG
+  {
+    version MJLVERS
+    {
+      int INTEGER(int) = 1;
+    
+    } = 1;
+  } = 0x20000001;
+
+
+
+ +

+ + + + + +
+
+int INTEGER(int) = 1;
+
+
+Server function now accepts an integer and returns an integer. +
+ + + + +

+ +


+

See Also:

+ + +VOID keyword. +
+

+

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

+ +


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

C Storage Classes.

+
+
+

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

+So what Storage Classes are available? +

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

+


+

auto - storage class

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

+


+

register - Storage Class

+register is used to define local variables that should be stored +in a register instead of RAM. This means that the variable has a maximum size +equal to the register size (usually one word) and cant have the unary '&' +operator applied to it (as it does not have a memory location). +
+	{
+	  register int  Miles;
+	}
+
+Register should only be used for variables that require quick access - such +as counters. It should also be noted that defining 'register' goes not mean +that the variable will be stored in a register. It means that it MIGHT be stored +in a register - depending on hardware and implimentation restrictions.

+


+

static - Storage Class

+ +Click here for static functions +

+static is the default storage class for +global variables. The two +variables below (count and road) both have a static storage class. +

+

+ + + + +
+
+
+     static int Count;
+     int Road;
+
+     main()
+     {
+       printf("%d\n", Count);
+       printf("%d\n", Road);
+     }
+
+
+
+

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

+

+ + + + +
+
+
+     void Func(void)
+     {
+       static Count=1;
+     }
+
+
+
+

+Here is an example

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

+

+ + + + +
+
+
+     char *Func(void);
+
+     main()
+     {
+       char *Text1;
+       Text1 = Func();
+     }
+
+     char *Func(void)
+     {
+       char Text2[10]="martin";
+       return(Text2);
+     }
+
+
+
+

+'Func' returns a pointer to the memory location where 'Text2' starts +BUT Text2 has a storage class of auto and will disappear +when we exit the function and could be overwritten by something else. The +answer is to specify: +

+

+ + + + +
+
+
+     static char Text[10]="martin";
+
+
+
+

+The storage assigned to 'Text2' will remain reserved for the duration if the +program. + +


+

extern - storage Class

+extern defines a global variable that is visable to ALL object +modules. When you use 'extern' the variable cannot be initalized as +all it does is point the variable name at a storage location that has +been previously defined. +
+
+
+ 	Source 1				Source 2
+        --------				--------
+
+
+	extern int count;			int count=5;
+
+        write()					main()
+        {					{
+          printf("count is %d\n", count);	  write();
+        }					}
+
+ +Count in 'source 1' will have a value of 5. If source 1 changes the +value of count - source 2 will see the new value. Here are some example +source files. +

+Source 1
+Source 2

+ +The compile command will look something like.

+

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

See Also:

+ +Data types. + + +

+ +


+

+

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

+


+
Martin Leslie +

+ + diff --git a/reference/C/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 @@ +Strings + +


+

Strings.

+
+

+

Pointers to strings.

+ +C does not have a "string" datatype. +To create a string you have to use a char array +or a char pointer. +If you are not familur with char arrays +I recomend that you read about them now. +

+To recap, a char pointer is +defined like this: +

+ + +
+
+ 
+     main()
+     {
+       char *Text;
+     }
+     
+
+
+

+ +All this program does is reserve storage that will hold an address. +At this point the address could be anything. To initalize Text +you can code: +

+ +
+
+    
+     main()
+     {
+       char *Text = "Thunder";
+     }
+     
+
+ + +Text now has the address of the first character in Thunder. +Graphically, things look like this. + +

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

+ +Please note the 00 at the end of Thunder. This is +the NULL character and is used to mark the +end of a string. +

+If we wanted to O/P the data pointed to by a char pointer + we can code. +

+ + +
+Source +
+
+
+     main()
+     {
+       char *Text1 = "Thunder";          /* Define and initalize */
+       char *Text2;                      /* Define only          */
+       
+       Text2 = "Bird";                   /* Point to some text   */
+       
+       printf("%s%s\n", Text1, Text2);
+     }
+     
+
+
+Result +
+
+
+      ThunderBird
+
+
+
+

+ +This is all very well, but there is a MAJOR problem! Thunder +and Bird are +constants, 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 +malloc to do just that. +

+ +


+

See Also:

+ + +VOID keyword. +
+

+

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

+ +


+
Martin Leslie + +
+ + 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 @@ +True or False + +
+
+

True or False.

+
+
+The concept of an expression evaluating to true or false is one of +the corner stones of C. BUT the language derives true and false in an +unusual way.

+Basicly there is no boolean value. The number 0 is considered to be false +and all other numbers are considered to be true....

+ +Please consider the following expressions. + +

+	(1 == 1) 	true
+	(1 != 1)	false
+	(i  = 1)   	true
+	(i  = 0)   	false
+	(i  = 1 + 1) 	true
+
+The first two examples should be clear but the last ones need explanation .

+The last three examples assign a value to a variable and a side effect of +assignment is to return the value assigned, it is this value that is tested +to be true or false.

+Looking at the last example: +

+	(i = 1 + 1)
+  	(i = 2)
+	(2)
+
+ + +

+


+

See Also:

+ +enum keyword +
+

+

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

+ +


+
Martin Leslie + +
Corrections made by Christopher Wolf + + + 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 @@ +Data type conversion + +
+

Data type conversion

+
+ +An operator must have +operands +of the same +type before it can carry out the operation. Because of this, C will perform +some automatic conversion of data types. +

+These are the general rules for binary operators (* + / % etc): +

+

+ +
+

See Also

+ +cast to force a type conversion. +
+ +typedef keyword. +
+

+

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

+ +


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