PLEASE NOTE: the upgrades to this server, secure.csse.uwa.edu.au, have not yet been completed.
Hopefully the changes will be completed on THURSDAY 8th December.
Web-based programs, such as csmarks, cssubmit, and the help fora, will be unavailable at some time on Thursday 8th.
  It's UWAweek 49

help2002

This forum is provided to promote discussion amongst students enrolled in CITS2002 Systems Programming.
Please consider offering answers and suggestions to help other students! And if you fix a problem by following a suggestion here, it would be great if other interested students could see a short "Great, fixed it!"  followup message.

Displaying selected article
Showing 1 of 919 articles.
Currently 6 other people reading this forum.


 UWA week 33 (2nd semester, week 4) ↓
SVG not supported

Login to reply

👍?
helpful
2:17pm Mon 15th Aug, Christopher M.

We know that the C processor receives our C program's source code before the C compiler, processes (modifies) the contents of the source code, and sends its output to the compiler. It can be instructive to see what the C preprocessor produces. We normally invoke the C compiler with cc and we can invoke the C preprocessor with cpp. If we write the simplest of C programs:
#include <stdio.h>

int main(int argc, char *argv[])
{
    printf("hello world\n");
    return 0;
}

and then just pass it to the C preprocessor:
prompt>  cpp try.c
(on my Mac, anyway) it produces 7200+ lines of output(!), most being the result of including the standard stdio.h header file, and our tiny C program appears (not needing any modification) right at the end. You may view the C preprocessor's output with:
prompt>  cpp try.c | less
and then leave less with a 'q'. You can also use the C preprocessor to see what it 'pre-defines' for your program. Firstly, let's see what it provides for any empty (zero-sized) file:
prompt  cpp -dM /dev/null | less
which gives 361 lines (on my Mac), or for our small C file using <stdio.h>
prompt>  cpp -dM try.c | less
now 1611 lines on my Mac. You may like to try these 'experiments' again, using the lab exercise involving rotate.c to see how the value of ROT was replaced.

The University of Western Australia

Computer Science and Software Engineering

CRICOS Code: 00126G
Written by [email protected]
Powered by history
Feedback always welcome - it makes our software better!
Last modified  1:17AM Sep 14 2022
Privacy policy