New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here


by: Eloy Ferry


Eloy Ferry
GPA 3.84


Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Class Notes
25 ?




Popular in Course


This 22 page Class Notes was uploaded by Eloy Ferry on Saturday September 26, 2015. The Class Notes belongs to E C E 371L at Clemson University taught by Staff in Fall. Since its upload, it has received 51 views. For similar materials see /class/214313/e-c-e-371l-clemson-university in ELECTRICAL AND COMPUTER ENGINEERING at Clemson University.

Similar to E C E 371L at Clemson





Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/26/15
Programming Style Phil Carns pcarnsparlclemsonedu Parallel Architecture Research Laboratory Summer 2003 Programming style why does it matter ED easier to work as a team ED simpli es code maintenance CD can reduce programming errors General concepts ED Always match the style of the project III may not necessarily match What you see in this lecture III helps project contributors understand code III always assume someone else will modify your code III make the project look consistent and professional General concepts cont ED plan ahead decide overall structure in advance ED build test harnesses early no really ED compile often and x all warnings ED gcc Wall Wstrict prototypes Case study ED for the remainder of the lecture we will work on a case study ED develop a piece of code from scratch ED point out some programing style decisions as we go Case study ED project develop a piece of code to track experimental mea surements and manipulate them III add new measurements III search for measurements III manipulate measurements Planning ED plan your source le layout rst in this case we need the following III one 0 le for the implementation eXpC III one h le exposing the API to programmers eXph III one 0 le to use as a test harness testc ED notice that expc and eXph match to make it obvious that they belong together Before writing any code 1 ED there are a few things we can do before writing any code III copyright information at the top of every source le C 2003 Clemson University See COPYING in top level directory III later on you can add a copying le that provides a con sistent license for all of the source Before writing any code 2 ED ifndef wrappers based on le name enclosing all h le code ifndef EXPH define EXPH the quotmeatquot of the header file goes here endif EXPH ED this prevents double inclusion of header information Planning the API CD it usually helps to plan out the full API before implementing III consistent function names eXpJXX in this case III consistent return values such as int 0 on success 1 on error III write out function prototypes and de nitions as stubs III comment each function de nition Code stubs ED always return an error code in stub functions ED always print an obvious error message in stubs ED this makes sure that no one accidentally uses them Function comments ED use project conventions if applicable or something like this 1 function name 2 What the function does including side effects 3 What the valid return values are expcalctotalmean Calculates the mean of all measurements The mean a output variable that is filled in upon completion returns 0 on success 1 on failure Return value decisions CD in the last example we pass out the result in an argument ED we could have just returned the mean instead CD but then how do you report errors CD you could state that negative means are invalid but that restricts problem domain and obscures semantics Function prototypes ED external functions put prototypes in header le ED internal functions put prototypes at top of c le ED if you use the right gcc ags it will complain if you don t set up prototypes nicely with good reason Almost ready to write code ED write a test harness rst if possible ED this allows you to test as you write code ED keep functions reasonably short III if a function is over 2 pages you probably are in trouble Where to put the code ED don t put anything in your headers that you don t have to CD if a function will only be used Within a single 0 le make it static ED both of the above tips help to modularize and protect code Commenting code body ED comment code as you write it not afterwards ED for complex functions put a big comment at the top to de scribe the steps it will do ED comments for general ideas and non intuitive syntax ED always use c style comments Legibility ED don t go out of your way to make code compact that s What compilers are for ED use long function names Where appropriate ED use consistent capitalization or lack thereof in my opinion ED use brackets around all condition blocks Assertions CD a handy sanity checking tool include ltasserthgt some condition you would like to assert assertx Assertions 2 ED assertions will halt execution if condition not met ED prints an error message ED makes it obvious when code is pushed beyond design limits ED assertions can be disabled with DNDEBUG Safety ED always check return values of functions ED especially malloc and scanf ED initialize all variables when you declare them ED memset any memory that you allocate


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."

Kyle Maynard Purdue

"When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the I made $280 on my first study guide!"

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.