Surviving C and PostgreSQL - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Surviving C and PostgreSQL

Description:

... Outline A Review of C PostgreSQL Basics Tour of Assignment 1 2Q A Review of C Arrays and ... Presentation PowerPoint Presentation Arrays and ... – PowerPoint PPT presentation

Number of Views:65
Avg rating:3.0/5.0
Slides: 9
Provided by: Matthe479
Category:

less

Transcript and Presenter's Notes

Title: Surviving C and PostgreSQL


1
Surviving C and PostgreSQL
  • CS186 Supplemental Session
  • 9/13/04
  • Matt Denny, Paul Huang, Murali Rangan
  • (Originally prepared by Shariq Rizvi, Wei Xu,
    Shawn Jeffery)

2
Outline
  • A Review of C
  • PostgreSQL Basics
  • Tour of Assignment 1
  • 2Q

3
A Review of C
  • Review Pitfalls of C Programming for Java
    Programmers
  • Pointers and Arrays
  • Strings
  • Segmentation Faults
  • For more information, consult The C
    Programming Language by Kernighan and Ritchie or
    tutorial on web site

4
  • Pointer variable containing address of another
    variable
  • float f / data variable /
  • float f_addr / pointer variable /
  • f_addr f / address operator /

5
f_addr 3.2 / indirection operator
/ float gf_addr /
indirectiong is now 3.2 / f 1.3
6
Arrays and Pointers
int month12 / month is a pointer to base
address 430 system allocates
12sizeof(int) bytes at 430
/ month3 7 / integer at address
(4303sizeof(int)) is now 7
/ ptr month 2 / ptr points to month2,
i.e. ptr (4302 sizeof(int))
438 / ptr5 12 / int at
address (4345sizeof(int)) is
now 12 same as month7 /
  • Now , month6, (month6), (month4)2,
    ptr4, (ptr4) are all the same integer
    variable.

7
Strings
include ltstdio.hgt main() char msg10 /
array of 10 chars / char p / pointer
to a char / char msg2Hello / msg2
Hello\0 / msg Bonjour /
ERROR. msg has a const address. Think of
space allocation/ p Bonjour / address
of Bonjour goes into p / p msg / OK /
p0 H, p1 i,p2\0 /
p and msg are now Hi Warning be careful if
you have space allocated for p!!/
8
Segmentation Fault?
  • You reference memory that the OS doesnt want you
    to
  • What to check?
  • Dereferencing a null pointer 99
  • Output or trace with a debugger
  • Check array bounds
Write a Comment
User Comments (0)
About PowerShow.com