Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Lecture 6 | Programming Paradigms (Stanford)

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
32,077
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jul 18, 2008

Lecture by Professor Jerry Cain for Programming Paradigms (CS107) in the Stanford University Computer Science department. In this lecture, Prof. Cain discusses C language programming by focusing on different forms of stack.

Programming Paradigms (CS107) introduces several programming languages, including C, Assembly, C++, Concurrent Programming, Scheme, and Python. The class aims to teach students how to write code for each of these individual languages and to understand the programming paradigms behind these languages.

Complete Playlist for the Course:
http://www.youtube.com/view_play_list?p=9D558D49CA734A02

CS 107 Course Website:
http://www.CS107.stanford.edu/

Stanford University:
http://www.stanford.edu/

Stanford University Channel on YouTube:
http://www.youtube.com/stanford/

Category:

Education

Tags:

Download this video

LICENSE: Creative Commons (Attribution-Noncommercial-No Derivative Works).

For more information about this license, please read: http://creativecommons.org/licenses/by-nc-nd/3.0/.

High-quality MP4 Learn more

  • likes, 2 dislikes

Link to this comment:

Share to:

Top Comments

  • At 29:00 assert(s->elemsize > 0) should be assert (elemsize > 0) because s->elemsize is not yet attributed to elemsize, so there is garbage in it.

  • Good stuff. I like this guy's enthusiasm.

see all

All Comments (28)

Sign In or Sign Up now to post a comment!
  • @glcrazy i think that was a typo.. he wanted to check elemSize not s->elemSize, to make sure it was not 0 before he set it to s->elemSize

  • @Ghouly89 you're right, thanks

  • @algnadjib That's not the reason why you don't need to cast the pointer.

    What happens is that the compiler implicitly casts the void * returned by malloc to the pointer type you need, in this case an int *. If the pointer remains a void *, or a typeless pointer, then it doesn't matter if we know that all pointers are 4 bytes wide, because we still have NO idea how big the object it is pointing to is.

  • @blackcompe cool! thanks!

  • @zengrz No, because your going to memcpy() into that space on the next invocation of stackpush(). E.g. $ - bottom of stack $|2|1|3| logLength = 2 So, 3 is the last element in the stack. The client calls stackpop(). I don't need to deallocate or erase anything, just the return value and set logLength accordingly. $|2|1|3| logLength--; So, 1 is the last element in the stack. Now the client calls stackpush(7). I just overwrite the next element since its garbage. logLength++; $|2|1|7|
  • @43:00 do you not have to deallocate the space that is supposed to be popped before exiting the stackpop function, since you used the 'memcpy' and not 'memcut' or something?

  • @kaarta no casting needed because every pointer is a 4 byte wide

  • This guy is a genius. Clear as water.

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more