The Setup of C

Exercise 0: The Setup

In this chapter you get your system setup to do C programming. The good news for anyone using Linux or Mac OSX is that you are on a system designed forprogramming in C. The authors of the C language were also instrumental in the creation of the Unix operating system, and both Linux and OSX are based on Unix. In fact, the install will be incredibly easy.

I have some bad news for users of Windows: learning C on Windows is painful. You can write C code for Windows, that's not a problem. The problem is all of the libraries, functions, and tools are just a little "off" from everyone else in the C world. C came from Unix and is much easier on a Unix platform. It's just a fact of life that you'll have to accept I'm afraid.

I wanted to get this bad news out right away so that you don't panic. I'm not saying to avoid Windows entirely. I am however saying that, if you want to have the easiest time learning C, then it's time to bust out some Unix and get dirty. This could also be really good for you, since knowing a little bit of Unix will also teach you some of the idioms of C programming and expand your skills.

This also means that for everyone you'll be using the command line. Yep, I said it. You've gotta get in there and type commands at the computer. Don't be afraid though because I'll be telling you what to type and what it should look like, so you'll actually be learning quite a few mind expanding skills at the same time.

Linux

On most Linux systems you just have to install a few packages. For Debian based systems, like Ubuntu you should just have to install a few things using these commands:

$ sudo apt-get install build-essential

The above is an example of a command line prompt, so to get to where you can run that, find your "Terminal" program and run it first. Then you'll get a shell prompt similar to the $ above and can type that command into it. Do not type the ``$``, just the stuff after it.

Here's how you would install the same setup on an RPM based Linux like Fedora:

$ su -c "yum groupinstall development-tools"

Once you've run that, you should be able to do the first Exercise in this book and it'll work. If not then let me know.

Mac OSX

On Mac OSX the install is even easier. First, you'll need to either download the latest XCode from Apple, or find your install DVD and install it from there. The download will be massive and could take forever, so I recommend installing from the DVD. Also, search online for "installing xcode" for instructions on how to do it.

Once you're done installing XCode, and probably restarting your computer if it didn't make you do that, you can go find your Terminal program and get it put into your Dock. You'll be using Terminal a lot in the book, so it's good to put it in a handy location.

Windows

For Windows users I'll show you how to get a basic Ubuntu Linux system up and running in a virtual machine so that you can still do all of my exercises, but avoid all the painful Windows installation problems.

... have to figure this one out.

Text Editor

The choice of text editor for a programmer is a tough one. For beginners I tell them to just use Gedit since it's simple and works for code. However, it doesn't work in certain internationalized situations, and chances are you already have a favorite text editor if you've been programming for a while.

With this in mind, I want you to try out a few of the standard programmer text editors for your platform and then stick with the one that you like best. If you've been using GEdit and like it then stick with it. If you want to try something different, then try it out real quick and pick one.

The most important thing is do not get stuck picking the perfect editor. Text editors all just kind of suck in odd ways. Just pick one, stick with it, and if you find something else you like try it out. Don't spend days on end configuring it and making it perfect.

Some text editors to try out are:

There is probably a different editor for every person out there, but these are just a few of the free ones that I know work. Try a few out, and maybe some commercial ones until you find one that you like.

WARNING: Do Not Use An IDE

An IDE, or "Integrated Development Environment" will turn you stupid. They are the worst tools if you want to be a good programmer because they hide what's going on from you, and your job is to know what's going on. They are useful if you're trying to get something done and the platform is designed around a particular IDE, but for learning to code C (and many other languages) they are pointless.

NOTE

If you've played guitar then you know what tablature is, but for everyone else let me explain. In music there's an established notation called the "staff notation". It's a generic, very old, and universal way to write down what someone should play on an instrument. If you play piano this notation is fairly easy to use, since it was created mostly for piano and composers.

Guitar however is a weird instrument that doesn't really work with notation, so guitarists have an alternative notation called "tablature". What tablature does is, rather than tell you the note to play, it tells you the fret and string you should play at that time. You could learn whole songs without ever knowing about a single thing you're playing. Many people do it this way, but if you want to know whatyou're playing, then tablature is pointless.

It may be harder than tablature, but traditional notation tells you how to play the music rather than just how to play the guitar. With traditional notation I can walk over to a piano and play the same song. I can play it on a bass. I can put it into a computer and design whole scores around it. With tablature I can just play it on a guitar.

IDEs are like tablature. Sure, you can code pretty quickly, but you can only code in that one language on that one platform. This is why companies love selling them to you. They know you're lazy, and since it only works on their platform they've got you locked in because you are lazy.

The way you break the cycle is you suck it up and finally learn to code without an IDE. A plain editor, or a programmer's editor like Vim or Emacs, makes you work with the code. It's a little harder, but the end result is you can work with any code, on any computer, in any language, and you know what's going on.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Write a program to simulate a process of translation from a logical address to physical address. Assumptions 1. Assume the file la.txt includes the sequence of generated addresses from CPU. 2. Use a part of memory as backing store that store data for a process. 3. The backing store size is 128 bytes 4. The size of process p is 128 bytes. 5. The contents of p is included in a file pdata.bin which is a binary file. 6. Use a part of memory as RAM. The size of physical memory is 256 bytes, from 0 to 255. All the physical memory is available, allocating starting from beginning in sequence. That is, allocate frame 0 first, then frame 1, then frame 2…. 7. The size of a frame is 32 bytes, i.e., 5 bits for the offset in a frame, total number of frames is 8. 8. At beginning, no page table is available for process p. Requirements Write a program to 1. Setup a simulating backing store in memory. Read the data from pdata.bin to this backing store. 2. Initialize a page table for process p, set the frame number to be -1 for each page, indicating that the page is not loaded into memory yet. 3. Read logical addresses one by one from la.txt. 4. For each logical address, a) if its page has been loaded into physical memory, simply find the frame number in the page table, then generate physical address, find and print out the physical address and data inside this address. b) if the page is used for the first time, i.e., in page table, its frame number is -1,then the page that contains this address should be loaded into a free frame in physical memory (RAM). Then update the page table by adding the frame number to the right index in the page table. Then repeat 4a). Refer to Figure 1 for the relationships and how physical memory, backing store, and CPU are simulated. Figure 1 How physical memory, backing store and CPU are simulated in this program assignment Hints: a) use a memory block pointed by a pointer or use an array as a simulation of backing store b) use functions fread or mmap for the binary file read. Search through the Internet for the usage of these functions. c) Use an array to simulate the memory. d) Use bit operators &, |, <<, and >> to get the bits in a logic address or form a physical address e) Use char for the type of data in the process, use unsigned char (8 bits) for the type of address. Coding & Submission 1. Using pure C to finish this program. 2. Put all the codes in one .c file named PA3_#####.c, replace “#####” as the last 5 digits of your student ID. 3. Put pdata.txt and la.txt in the same folder as PA3_#####.c, which the need .txt file can be open directly by filename instead of absolute path. 4. Submit only the .c file mentioned above.使用C语言完成
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值