SlideShare a Scribd company logo
1 of 46
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],pointer to a function that takes an integer argument and a float argument and returns an integer pointer to a function that takes an integer argument and a float argument and returns a  pointer  to an integer An  array  of pointers to functions – Each function takes an integer argument and a float argument and returns a pointer to an integer
[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
Void Pointers CS 3090: Safety Critical Programming in C
[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object]
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
CS 3090: Safety Critical Programming in C
A C programmer cannot not decides what will be the memory address of any variables.
[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C
[object Object]
[object Object],CS 3090: Safety Critical Programming in C Far Pointer
09/27/11 CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
CS 3090: Safety Critical Programming in C ,[object Object],[object Object]
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object]
#include<stdio.h> int main(int argc, char *argv[]) { printf(&quot;No. of Argument::%d&quot;,argc); int cnt=argc-1; while(cnt>=1) { printf(&quot;Entered numbers are%s&quot;,argv[cnt]); cnt--; }return 0;}
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
typedef struct IntNode { int value; struct IntNode *next; } INTNODE; INTNODE *search_list(INTNODE *node, int const key) { while (!node) { if (node->value == key) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C OK, but it only works for nodes containing integer data. If you want a list of strings, you’ll need to define a new type and new function.
typedef struct Node { void *value; struct Node *next; } NODE; void construct_node(NODE *node, void *value, NODE *next) { node->value = value; node->next = next; } NODE *new_node(void *value, NODE *next) { NODE *node = (NODE *)malloc(sizeof(NODE)); construct_node(node, value, next); return node; } CS 3090: Safety Critical Programming in C void*  is compatible with any pointer type. So, this member can hold (a pointer to) any value!
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
NODE *search_list(NODE *node, void const *key, int (*compare)(void const *, void const *)) { while (node) { if (!compare(node->value, key)) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C Assumption:  compare  returns zero if its parameter values are equal; nonzero otherwise
[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C Note: you may get a warning, since  strcmp  is not strictly of the right type: its parameters are of type  char *  rather than  void * &  is optional here – compiler will implicitly take the address
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C Array of pointers to functions. Each function takes two  double s and returns a  double
[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C
[object Object],[object Object],[object Object],[object Object],[object Object],CS 3090: Safety Critical Programming in C 3 argc argc [0] [1] [2] [3] NUL
int main(int argc, char **argv) { char id[ID_LIMIT]; switch(argc) { case 1: generate_ID(id); break; case 3: if (strcmp(argv[1], &quot;-i&quot;) exit(INVALID_ARG); strcpy(id, argv[2]); break; default: exit(INVALID_ARG_COUNT); } register(id); } CS 3090: Safety Critical Programming in C
[object Object],CS 3090: Safety Critical Programming in C

More Related Content

What's hot

What's hot (19)

Assignment c programming
Assignment c programmingAssignment c programming
Assignment c programming
 
Theory1&amp;2
Theory1&amp;2Theory1&amp;2
Theory1&amp;2
 
C Programming Assignment
C Programming AssignmentC Programming Assignment
C Programming Assignment
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Chapter Eight(2)
Chapter Eight(2)Chapter Eight(2)
Chapter Eight(2)
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
Code generator
Code generatorCode generator
Code generator
 
Savitch ch 08
Savitch ch 08Savitch ch 08
Savitch ch 08
 
Pointers in C Language
Pointers in C LanguagePointers in C Language
Pointers in C Language
 
Lecturer23 pointersin c.ppt
Lecturer23 pointersin c.pptLecturer23 pointersin c.ppt
Lecturer23 pointersin c.ppt
 
Introduction to pointers and memory management in C
Introduction to pointers and memory management in CIntroduction to pointers and memory management in C
Introduction to pointers and memory management in C
 
C pointers
C pointersC pointers
C pointers
 
Ponters
PontersPonters
Ponters
 
C programming session 05
C programming session 05C programming session 05
C programming session 05
 
Pointers_c
Pointers_cPointers_c
Pointers_c
 
C
CC
C
 
Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)   Intermediate code generation (Compiler Design)
Intermediate code generation (Compiler Design)
 
CPP Programming Homework Help
CPP Programming Homework HelpCPP Programming Homework Help
CPP Programming Homework Help
 
String & its application
String & its applicationString & its application
String & its application
 

Viewers also liked

Viewers also liked (7)

9. pointer, pointer & function
9. pointer, pointer & function9. pointer, pointer & function
9. pointer, pointer & function
 
Data structure lecture 1
Data structure   lecture 1Data structure   lecture 1
Data structure lecture 1
 
C pointer
C pointerC pointer
C pointer
 
6 pointers functions
6 pointers functions6 pointers functions
6 pointers functions
 
Pointers in C
Pointers in CPointers in C
Pointers in C
 
C Pointers
C PointersC Pointers
C Pointers
 
Human values & professional ethics
Human values & professional ethicsHuman values & professional ethics
Human values & professional ethics
 

Similar to Advanced+pointers

C programming session 01
C programming session 01C programming session 01
C programming session 01Dushmanta Nath
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)tech4us
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programmingvipulkondekar
 
C Programming Language
C Programming LanguageC Programming Language
C Programming LanguageRTS Tech
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdfSergiuMatei7
 
Introduction to c
Introduction to cIntroduction to c
Introduction to camol_chavan
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptxvijayapraba1
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Functionimtiazalijoono
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentationnadim akber
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docxeugeniadean34240
 
Lesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticLesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticPVS-Studio
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptxRohitRaj744272
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to cHattori Sidek
 

Similar to Advanced+pointers (20)

Quiz 9
Quiz 9Quiz 9
Quiz 9
 
C programming session 01
C programming session 01C programming session 01
C programming session 01
 
C notes for exam preparation
C notes for exam preparationC notes for exam preparation
C notes for exam preparation
 
Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)Pointers (Pp Tminimizer)
Pointers (Pp Tminimizer)
 
C Introduction and bascis of high level programming
C Introduction and bascis of high level programmingC Introduction and bascis of high level programming
C Introduction and bascis of high level programming
 
C Programming Language
C Programming LanguageC Programming Language
C Programming Language
 
C –FAQ:
C –FAQ:C –FAQ:
C –FAQ:
 
C introduction
C introductionC introduction
C introduction
 
Programming in C - interview questions.pdf
Programming in C - interview questions.pdfProgramming in C - interview questions.pdf
Programming in C - interview questions.pdf
 
Introduction to c
Introduction to cIntroduction to c
Introduction to c
 
Fundamentals of Programming Constructs.pptx
Fundamentals of  Programming Constructs.pptxFundamentals of  Programming Constructs.pptx
Fundamentals of Programming Constructs.pptx
 
Fundamental of C Programming Language and Basic Input/Output Function
  Fundamental of C Programming Language and Basic Input/Output Function  Fundamental of C Programming Language and Basic Input/Output Function
Fundamental of C Programming Language and Basic Input/Output Function
 
Complete c programming presentation
Complete c programming presentationComplete c programming presentation
Complete c programming presentation
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
20145-5SumII_CSC407_assign1.htmlCSC 407 Computer Systems II.docx
 
Lesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmeticLesson 13. Pattern 5. Address arithmetic
Lesson 13. Pattern 5. Address arithmetic
 
c_pro_introduction.pptx
c_pro_introduction.pptxc_pro_introduction.pptx
c_pro_introduction.pptx
 
C tutorials
C tutorialsC tutorials
C tutorials
 
Ch2 introduction to c
Ch2 introduction to cCh2 introduction to c
Ch2 introduction to c
 
Csdfsadf
CsdfsadfCsdfsadf
Csdfsadf
 

Recently uploaded

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...M56BOOKSTORE PRODUCT/SERVICE
 

Recently uploaded (20)

BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
KSHARA STURA .pptx---KSHARA KARMA THERAPY (CAUSTIC THERAPY)————IMP.OF KSHARA ...
 

Advanced+pointers

  • 1.
  • 2.
  • 3.
  • 4. Void Pointers CS 3090: Safety Critical Programming in C
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12. CS 3090: Safety Critical Programming in C
  • 13. A C programmer cannot not decides what will be the memory address of any variables.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20. CS 3090: Safety Critical Programming in C
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27. 09/27/11 CS 3090: Safety Critical Programming in C
  • 28.
  • 29.
  • 30.
  • 31.
  • 32. #include<stdio.h> int main(int argc, char *argv[]) { printf(&quot;No. of Argument::%d&quot;,argc); int cnt=argc-1; while(cnt>=1) { printf(&quot;Entered numbers are%s&quot;,argv[cnt]); cnt--; }return 0;}
  • 33.
  • 34. typedef struct IntNode { int value; struct IntNode *next; } INTNODE; INTNODE *search_list(INTNODE *node, int const key) { while (!node) { if (node->value == key) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C OK, but it only works for nodes containing integer data. If you want a list of strings, you’ll need to define a new type and new function.
  • 35. typedef struct Node { void *value; struct Node *next; } NODE; void construct_node(NODE *node, void *value, NODE *next) { node->value = value; node->next = next; } NODE *new_node(void *value, NODE *next) { NODE *node = (NODE *)malloc(sizeof(NODE)); construct_node(node, value, next); return node; } CS 3090: Safety Critical Programming in C void* is compatible with any pointer type. So, this member can hold (a pointer to) any value!
  • 36.
  • 37. NODE *search_list(NODE *node, void const *key, int (*compare)(void const *, void const *)) { while (node) { if (!compare(node->value, key)) break; node = node->next; } return node; } CS 3090: Safety Critical Programming in C Assumption: compare returns zero if its parameter values are equal; nonzero otherwise
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43.
  • 44.
  • 45. int main(int argc, char **argv) { char id[ID_LIMIT]; switch(argc) { case 1: generate_ID(id); break; case 3: if (strcmp(argv[1], &quot;-i&quot;) exit(INVALID_ARG); strcpy(id, argv[2]); break; default: exit(INVALID_ARG_COUNT); } register(id); } CS 3090: Safety Critical Programming in C
  • 46.