CSCS1320 C/C++ Programming
PROJECT: C INTEGER TYPES (cit0)
OBJECTIVE
To begin our exploration of programming, starting with an investigation into the various integer data types available in C, along with their properties.
GRABIT
To assist with consistency across all implementations, data files for use with this project are available on lab46 via the grabit tool. Be sure to obtain it and ensure your implementation properly works with the provided data.
lab46:~/src/SEMESTER/cprog$ grabit cprog cit0
Please study any provided code or supporting documents, and look up, experiment, and ask questions on aspects that you do not understand.
SCOPE
This project will be exploring the nature of some of the data types available to us in the C Programming Language. How much space is allocated to each type, and what are the ranges available for each type?
A program is provided that will display (to STDOUT) the size (in bytes), the lower and upper bounds of each studied type, and some other related information.
The data types covered for this project will include signed (can be positive/negative) and unsigned (absolute values, no sign) variations of:
charshort intintlong intlong long int
The sizeof() and fprintf() functions, as well as arithmetic and logical operators, will be utilized in performing much of the work.
TASK
Your task is to first study and understand what the provided code is doing. It is expected you will ask questions on discord to gain clarification.
There is extensive commenting in place in the source file for you to read, which will explain many of the details about each item of information being obtained.
Once you have an understanding of what is going on, extend the code to support the other types (both signed and unsigned). In total, you should have TEN total sections.
HEXADECIMAL
When dealing with things like addresses and raw data on the computer (a binary device), it is common practice to interact in some power-of-two base, with base 16 (hexadecimal) being the most common in use today.
I would encourage you to memorize and become very familiar with navigating the following table:
| base 2 | base 8 | base 10 (unsigned) | base 10 (signed) | base 16 |
|---|---|---|---|---|
0000 |
000 |
0 |
+0 |
0x0 |
0001 |
001 |
1 |
+1 |
0x1 |
0010 |
002 |
2 |
+2 |
0x2 |
0011 |
003 |
3 |
+3 |
0x3 |
0100 |
004 |
4 |
+4 |
0x4 |
0101 |
005 |
5 |
+5 |
0x5 |
0110 |
006 |
6 |
+6 |
0x6 |
0111 |
007 |
7 |
+7 |
0x7 |
1000 |
010 |
8 |
-8 |
0x8 |
1001 |
011 |
9 |
-7 |
0x9 |
1010 |
012 |
10 |
-6 |
0xA |
1011 |
013 |
11 |
-5 |
0xB |
1100 |
014 |
12 |
-4 |
0xC |
1101 |
015 |
13 |
-3 |
0xD |
1110 |
016 |
14 |
-2 |
0xE |
1111 |
017 |
15 |
-1 |
0xF |
It might be worthwhile to ask questions about the nature of the values on this table on the class discord, to gain a better understanding of why these values are here, how they were derived, and what value they bring to our interaction with computers.
COMPILING
The compilation process for working with your source code is as follows:
lab46:~/src/SEMESTER/cprog/cit0$ gcc -Wall --std=gnu18 -o cit0 cit0.c
lab46:~/src/SEMESTER/cprog/cit0$
Assuming there are no syntax errors or warnings, and everything compiled correctly, you should just get your prompt back. In the event of problems, the compiler will be sure to tell you about them.
Conceptually, the arrangement is as follows:
gcc -Wall --std=gnu18 -o BINARYFILE SOURCEFILE
The BINARYFILE comes immediately after the -o, NOT the
SOURCEFILE (the source file must never immediately follow a
-o). It can precede, and such is perfectly valid (especially if you
feel that way more intuitive).
The -Wall (treat all warnings as errors, increase general verbosity
about warnings) and --std=gnu18 (switch compiler to use a newer
standard of the C language, with GNU extensions) are options given to the
compiler.
EXECUTION
To execute your binary, we need to specify a path to it, so we use ./, which basically references the current directory:
lab46:~/src/SEMESTER/cprog/cit0$ ./cit0
signed char
=========================================
total size in bytes: 1
total size in bits: 8
value contains: 17
value exists in memory at: 0x7ffc1a16d967
minimum value represented: -128
maximum value represented: 127
possible distinct values: 256
=========================================
Your completed program will have far more output: additional sections each representing one of the integer type combinations (a total of 10).
SUBMISSION
To successfully complete this project, the following criteria must be met:
- Code must compile/execute cleanly (no notes, warnings, nor errors)
- Code must be nicely and consistently indented
- Code must be well commented
- Do NOT double space your code. Group like statements together.
- Track/version the source code in your private semester repository
- Submit a copy of your source code to me using the submit tool
To submit this program to me using the submit tool, run the following command at your LAB46 prompt:
lab46:~/src/SEMESTER/cprog/cit0$ make submit
You should get some sort of confirmation indicating successful submission if all went according to plan. If not, check for typos and or locational mismatches.
What I'll be looking for:
RUBRIC
I'll be evaluating the project based on the following criteria:
104:cit0:final tally of results (104/104)
*:cit0:grabit the code on lab46 by Sunday before deadline [13/13]
*:cit0:code is pushed to private semester repository [13/13]
*:cit0:proper output formatting per specifications [13/13]
*:cit0:clean compile, no compiler messages [13/13]
*:cit0:each integer type explored in full [26/26]
*:cit0:program conforms to project specifications [26/26]
NOTE: spirit of the project includes using hexadecimal values and bitwise logic operators to set the pertinent upper/lower bounds.
Additionally:
- Solutions not abiding by spirit of project will be subject to a 50% overall deduction
- Solutions not utilizing descriptive why and how comments will be subject to a 25% overall deduction
- Solutions not utilizing indentation to promote scope and clarity or otherwise maintaining consistency in code style and presentation will be subject to a 25% overall deduction
- Solutions not organized and easy to read (assume a terminal at least 90 characters wide, 40 characters tall) are subject to a 25% overall deduction