Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Data structure implementation with Linked lists.

Post

Data structure implementation with Linked lists.

+0
−3

Could someone explain this part of the coding for data structures & linked list? I actually got this code from a textbook but no matter how I read the textbook, I still don't get the concept & what it means. Thanks :")

#include<stdio.h>
#include<stdlib.h>
struct listNode{
    char data;
    struct listNode *nextPtr
};

typedef struct listNode ListNode;
typedef ListNode *ListNodePtr;

void insert(ListNodePtr *sPtr, char value);
char delete(ListNodePtr *sPtr, char value);
int isEmpty(ListNodePtr sPtr);
void printList(ListNodePtr currentPtr);
void instructions(void);

int main (void){
    //some coding
}`
History
Why does this post require moderator attention?
You might want to add some details to your flag.
Why should this post be closed?

2 comment threads

Don't typedef pointers (7 comments)
Linked list fundamentals (2 comments)
Don't typedef pointers
Lundin‭ wrote over 2 years ago

Hiding pointers behind typedef is considered very bad practice. If you got that from a book, it's not a good book. The actual parameters here are struct listNode **sPtr which explains why the pointed-at address can be modified - to for example point at space obtained by a malloc call inside the function.

r~~‭ wrote over 2 years ago · edited over 2 years ago

Considered by many very bad practice, sure. This is a popular, but not universally-held opinion. (Whether you're more of a C person or a C++ person seems to be somewhat correlated to whether you think typedef'd pointers are okay.)

Lundin‭ wrote over 2 years ago

r~~‭ I'd say that the vast majority of C programmers find it bad practice. You can for example check out all the close to unanimous criticism regarding how bad the Windows API type system was designed, where the main arguments against it was its use of "Hungarian notation" and pointers hidden behind typedefs.

r~~‭ wrote over 2 years ago

Lundin‭ The C programmers of libxml seem to be fine with it. As do the C programmers of the FreeType library. And also the programmers who've contributed to CPython.

I'm not saying they're right and you're wrong. Maybe all of the above projects would be improved by not using these typedefs. But can we at least agree that the pattern is common enough that a book that uses it shouldn't be dismissed out of hand as a bad book?

Lundin‭ wrote over 2 years ago

r~~‭ You aren't going to prove anything by linking random open source libraries by random people - only by providing the take from well-known C gurus. Now as it happens on SO we have some 20-30 of such very skilled C programmers pretty much unanimously agreeing that hiding pointers behind typedefs are bad and dangerous.

r~~‭ wrote over 2 years ago

I'm, uh, not sure why I or anyone should take the opinions of unnamed, unlinked SO users more seriously than those of the authors of the very widely used software that I linked. But I think I'm going to check out of this argument now. Reader, make up your own mind how credible this claim is.

Lundin‭ wrote over 2 years ago · edited over 2 years ago

r~~‭ It's not trivial to get 100k+ rep and a C gold badge at SO. Also it's people I've interacted with for many years and I know how good they are at C programming. Unlike random people in the average open-source project, who tend to range between mediocre and average. As for "wildly used", that certainly goes for the Windows API and pretty much everyone agrees that its type system is horrible.