What makes D a good language? [closed] - c

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
My professor recommended I do my senior capstone in D. What can it be used for? What makes it good? He compared it to C/C++ and said it's better. Why?
This post just makes D less attractive to work with:
Why isn't D picking up?

Compared to C and C++, it is safer, meaning that it cannot create the same sorts of segmentation faults by accessing uninitialized or disallowed memory. It also wouldn't allow misunderstanding object types like C/C++ casts can do with pointers and explicit memory allocation and deallocation. This makes the language "cleaner" feeling in some sense.
Prior to C++ standard version 2008, D also supported better delegation. Nowadays C++ is pretty close to D delegation capabilities by providing perfect forwarding.
D delegation: http://www.docwiki.net/view.php?pageid=97
C++ perfect forwarding: https://www.justsoftwaresolutions.co.uk/cplusplus/rvalue_references_and_perfect_forwarding.html

Related

Does Memory allocation in C is a machine dependent? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Does Memory allocation in C is a machine dependent?
I want my program to be transferred from a UNIX system to another system without any problem.
As #mediocrevegetable1 said in the comments, as long as you use functions from the standard library, it should work. (But just make sure that you used an ANSI C compiler before, and to use an ANSI C compiler when compiling for another system. You can see Here a list of ANSI C compilers.)

What is the meaning of malloc, realloc, calloc? I want to know full name of these functions [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 2 years ago.
Improve this question
I have tried to find it in google, but I couldn't.
I am studying C.
And now my stage is pointer and function about management memory.
But malloc, realloc, calloc...etc are hard to memorize.
So I want to know the full context. It will help to remember their meaning.
I do not speak English well. So my writing may be weird.
Please understand. Thanks for reading.
Memory Allocation (and reallocation etc...)
There is an awful lot to say about these functions but check out this article for a start.
And if you can still buy it read "The C Programming Language" by Brian Kernighan and Dennis Richie. A MUST Read

Why doesn't the C language have subrange type as Pascal does? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 4 years ago.
Improve this question
Why does the C language have an enum type but not a range type as Pascal does?
In Pascal we write this: type index = 1...100; or like this:
type letter = 'a'...'z';.
The designers of the C language implemented a very simple language whose features were only those that could be (for the most part) directly translated into to one or a handful of machine-code instructions. Anything that could not be done easily by the CPU had to be provided by a function call.
This makes the compiler very easy to write and also ensures that it is easier to see where performance problems might be.
Implementing a range takes several machine code instructions. Also, if it is used as a type qualifier it means that range checking has to be added to all arithmetic operations which requires further machine code instructions.
There are a lot of other constructs that are supported by other languages that are not supported in C except through function calls (dynamic memory allocation, string manipulation, maps, etc).

What are some modern C idioms/guidelines to prevent memory related bugs? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
In the past few years, I can see a lot of C++ best practices recommended everywhere. The C++ guidelines aren't applicable to C even to a smaller degree. Particularly for people coming from a relatively high level language like C++ or Java (like myself), programming in C seems very dangerous.
I know that C is too low level a language to make any guarantees, but is there anything I must be careful of while writing C code so that I can minimize the chances of memory related bugs?
There are many techniques reffered to as defensive programming, too many to list here. For instance, you may adopt to always set pointer to NULL, when you free the allocated memory:
free(p);
p = NULL;
This avoids leaving p as a dangling pointer. The one obvious benefit is that if one calls free again on p, it would not do anything, so you potentially avoid the double free issue.
The second method is to use numerous tools that may help you track the ubiqutous mistakes such as buffer overflow, just to mention Valgrind and AddressSanitizer.

What are the pros and cons for opaque pointers vs id numbers using the C programming language? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm currently using opaque pointers as my standard technique for encapsulation, but looking at the OpenGL API makes me think that using id numbers could be a better choice. I would like some advice from seasoned C programmers (I've only been using the language actively for ~2 years).
Here are my initial thoughts that I would like confirmed or corrected.
Possible pros for Id numbers:
Using object/memory pools in the implementation is rather straight forward if using id numbers
The id number does not have to map to the system memory (could reference graphics memory in the GL case)
Possible cons for Id numbers:
Makes the implementation slightly more complex
There is a similar question that takes into account the situation of using shared libraries:
Should I use integer ID or pointers for my opaque objects?
My question is not about shared libraries, it's about the general case of hiding implementation details from user code.
I suppose you could typedef a MyObjectHandle to enable the library to switch between id number and opaque pointer.
The question is:
What are the pros and cons for opaque pointers vs id numbers using the C programming language?

Resources