It's UWAweek 48

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 the 2 articles in this topic
Showing 2 of 919 articles.
Currently 5 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.


SVG not supported

Login to reply

👍?
helpful
9:25am Wed 17th Aug, Sae-Hwa Y.

In lab 3 q7, modification-time and file size have types time_t and size_t respectively. These are aliases so I would have to find out which main type they map to in order to use the correct format specifier while printing them.

Would running cpp <file> then searching through the output for typedef be a good approach or should I use another method to determine which format specifier to use?

Thank you for sharing these tips!

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