|
C ProgrammingThis article describes the internals of how to create, debug, and execute programs in the C programming language. Google Computers > Programming > Languages > C "C is quirky, flawed, and an enourmous success." Dennis Ritchie (C's co-inventor) | Topics this page:
|
|
C Language Specification History
|
Classic C Development Workflow
|
|
Interactions Among Parts of a C Program
Enclosing include files between < and > brackets tells the compiler to look for them in the standard include directory.
The data type of each input and output argument passed in and out of a function is defined with a parameter list A function that provide a return value of type void is called a procedure. The body within a function can contain declarations for local variables activated when execution reaches the function body.
|
C Documentation
Reviewing 'C' - Introduction by Jonathan Hill C-Tutorial: Programming for LCC-Win32 (395 pages) by Jacob Navia $21 Programming in ANSI C (April 1, 1994) by Stephen G. Kochan is highly recommended for an introductory text. Kochan also wrote books in UNIX. $50 Topics in C Programming (John Wiley & Sons Inc, June 1, 1991) by Kochan, Stephen G.; Wood, Patrick H. $110 Pure C Programming (Prentice Hall, 31-Aug-1998) by Amir Afzal $70 C : How to Program (Prentice Hall, 01-Jan-1994) by Deitel, H. M.;Deitel, P. J. Practical C Programming Nutshell Handbook (Cambridge ; Sebastopol, Calif. O'Reilly and Associates, 3rd Ed . 1997) one of several by Steve Oualline Memory Management: Algorithms and Implementation in C/C++ Windows Programming/development (Plano, Tex. Wordware Publishing, 2003) by Bill Blunden Standard C Date/time Library: Programming the World's Calendars and Clocks (Lawrence, KS: Berkeley, Calif. CMP Books, 1998) by Lance Latham, a professor at CUNY Albany The book comes with a CD-ROM of (licensed unchangeable) C functions in the Standard C Date/Time Library (STDTL.dll) explained in the book (written by Dan Bock for Windows 95 and NT) It covers ISO 8601 standard time plus non-Western and ancient calendar systems. Function JD0_to_gregorian has a bug, so copy into it code from JD0_to_gregorian_proleptic. Memory as a Programming Concept in C and C++ Cambridge University Press © 2004 (272 pages) by Frantisek Franek |
Classic .C Source Code Basics
|
Running Classic C Programs
hello.exe
This invokes an executable file. operating system commands and script files can also be specified. Linkers read the object files created during compilation by compiler software. To find the version of the gcc compiler:
gcc --version
To find the directories searched by the compiler:
gcc -print-search-dirs The list of shared object libraries is defined in enviornment variable LD_LIBRARY_PATH environment variable. To run a program from within a debugger, invoke the debugger associated with the compiler. For example:
fasd hello.exe
gdb hello.exe
|
Compilers and Debuggers
In the GNU compiler suite the linker is called ld. However you should not run ld directly except under very special circumstances. Libraries have the file extension .a
|
C# .NET CompilationThe Microsoft Visual C++ Toolkit 2003 provides the core tools for developers to compile and link C++-based of managed code applications for Windows and the .NET Common Language Runtime. It uncludes the Microsoft C/C++ Optimizing Compiler and Linker; C Runtime Library with the C++ Standard Library Microsoft .NET Framework Common Language Runtime with sample code.Tools for C# programming are a part of Microsoft's Visual Studio product line that include a visually oriented GUI (Graphic User Interface), which initiates compilation when the programmer presses F5 or clicks on the icon associated with compilation. The output exe is stored by default in the bin\Debug subdirectory under where the project file is located.
After putting the .NET Framework folder in the Windows Path environment variable
csc xxx.cs
csc.exe /t:exe /checked /debug+ /out:xxx.exe xxx.cs
The /debug+ parameter specifies debugging files to be generated. The /out: parameter specifies the location and file name for compiler output.
csc.exe /t:library /checked /debug+ /out:...\bin\yyy.dll xxx.cs
If you're using the VS.NET IDE, if you add a statement such as "using System.Management" in the .cs code before right clicking on "References" and selecting and adding a spcific version of the component being referenced, this message appears:
|
Make Files and Using Compressed Files
A Makefile is not invoked directly.
|
Debugging C ProgramsFor a list of commands:
> ?
To set a breakpoint in class file pgm's main method:
> stop in pgm.main
To execute until the breakpoint:
> run
For a listing of the source at the => position:
[] list
cont In C#, to set a breakpoint at line 100: cordbg CSharpProgram.exe !b CSharpProgram.cs:100 | The FXCop for C# programs code analysis tool checks .NET managed code assemblies for conformance to Microsoft .NET Framework Design Guidelines and custom rules created by the provided SDK. It uses reflection, MSIL parsing, and callgraph analysis to inspect assemblies for more than 200 defects The tool has both GUI and command line versions, ErrorBank, the .NET Error Repository crawler browses newsgroups and tries to collect only threads that have a description of an error/exception and solution to the problem discussed by developers. |
C IDEs (Integrated Development Environments)
For those who only want a better editor than Notepad (which appends “.txt” to the end of file names): Alternative IDEs: To use Visual Studio to compile ANSI C programs:
Annoyances to remember when using Visual Studio.NET: So after changing default name Form1 to frmMain, remember to also change it in source code static void Main() |
|
Utilities For C Source CodeTo use NUnit from public domain Sourceforge, in your class library project reference c:\program files\NUnit\bin\NUnitCore.dll (or wherever you have it installed) and add using NUnit.Framework;See this article
|
Accessing ConsoleFor a minimum classic C Windows program:
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance,
PSTR szCmdLine, int iCmdShow)
return (0); This "launcher" program enables "relative path" by 1) getting its own file path location, 2) chopping off its own name 3) appending the FOLDER_NAME (under it), 4) uses that for the startup directory path, then 5) appends the EXE_NAME and 6) starts the program. #include |
Common Libraries
If your program invokes Windows GUI functions, these headers are also needed:
|
Mo' Class Libraries
To supplement Sun's C Foundation Classes (JFCs) and Swing and Abstract Windowing Toolkit (AWT)
|
Due to a bug in Communicator, you must hold down the shift key and then click the link to download class files.) |
C AlgorithmsIn C, the behavior of a class is determined by its functions (rather than Java methods). Open source DBNavigator that has a VCR-like interface for navigating data and managing records. Record navigation is provided by the First, Previous, Next, and Last buttons. Record management is provided by the Create, Delete, Update, and Cancel buttons. It contains a huge portion of what every database application needs to perform. | The Deitel Family's books are wordy and expensive ($75), but colorful. C# For Experienced Programmers JoeGrip says you can learn C# in just 5 hours with their interactive audio courses online. |
Compiling with C#To compile and generate XML documentation within csc.exe /out:CSharpProgram.exe CSharpProgram.cs /doc:CSharpProgram.xmlThe C# compiler looks for XML wrapped comments after three slashes: /// <summary> /// Summary of program /// </summary> |
Visual Studio add-ons for C# developers Microsoft C# Programming for the Absolute Beginner (Indianapolis, IN: Premier Press, May 2002) by Andrew Harris of IUPUI — examples show how to develop simple games, so would be fun for kids.
|
C# Coding Guidelines, Standards, and Conventions |
|
Object Identifier Naming & Duration
The identifiers used to name variables and references include attributes name, data type, size, and value.
Identifiers must start with a letter, $ or _ (underline), but not a number.
The state of an object is determined by the values stored in its variables. An identifier's duration in memory is also called its lifetime.
The keyword this. is used to reference local variables named the same as variables defined at the class instance level. This is not valid for static methods. An identifier's scope defines where the identifier can be referenced within a program. |
|
Data Structures
| A Laboratory Course in C++ Data Structures (Boston, Mass. Jones & Bartlett Publishers, Inc., 2003) by Roberg“e, Jim.; Brandle, Stefan.; Whittington, David. C++ Plus Data Structures (Boston, MA Jones & Bartlett Publishers, Inc., 2003) by Dale, Nell B. |
C Developer Resources |
C Style Guides |
Pointers
|
|
Related:
| Your first name: Your family name: Your location (city, country): Your Email address: |
Top of Page
Thank you! |