Search results
Top results related to what are the function of dictionary keys in c world
Top Answer
Answered Jul 19, 2017 · 3 votes
- Same as regular typdefs, incredibly useful for 2 and 4. Instead of typing the whole thing, you can now use myFuncDef
- A function declaration for a function that recieves a function pointer. A function that takes a function pointer of 1. would thus look int add2to3(myFuncDef functionPtr);
- -
- A function that takes an int and (probably based on that) returns you a function pointer. Using the typedef it would have looked like myFuncDef functionFactory(int n);
Without typedefs these chains of pointers to pointers could get incredibly long as can be seen in this question: C syntax for functions returning function pointers
1/5
Top Answer
Answered Jan 06, 2019 · 68 votes
Both C and C++ give you a lower level of abstraction that, with increased complexity, provides a breadth of access to underlying machine functionality that are not necessarily exposed with other languages. Compared to C, C++ adds the convenience of a fully object oriented language(reduced development time) which can, potentially, add an additional performance cost. In terms of real world applications, I see these languages applied in the following domains:
C
- Kernel level software.
- Hardware device drivers
- Applications where access to old, stable code is required.
C,C++
- Application or Server development where memory management needs to be fine tuned (and can't be left to generic garbage collection solutions).
- Development environments that require access to libraries that do not interface well with more modern managed languages.
- Although managed C++ can be used to access the .NET framework, it is not a seamless transition.
C# provides a managed memory model that adds a higher level of abstraction again. This level of abstraction adds convenience and improves development times, but complicates access to lower level APIs and makes specialized performance requirements problematic.
It is certainly possible to implement extremely high performance software in a managed memory environment, but awareness of the implications is essential.
The syntax of C# is certainly less demanding (and error prone) than C/C++ and has, for the initiated programmer, a shallower learning curve.
C#
- Rapid client application development.
- High performance Server development (StackOverflow for example) that benefits from the .NET framework.
- Applications that require the benefits of the .NET framework in the language it was designed for.
Johannes Rössel makes the valid point that the use C# Pointers, Unsafe and Unchecked keywords break through the layer of abstraction upon which C# is built. I would emphasize that type of programming is the exception to most C# development scenarios and not a fundamental part of the language (as is the case with C/C++).
Other Answers
Answered Apr 01, 2009 · 78 votes
Bear in mind that I speak ASFAC++B. :) I've put the most important differentiating factor first.
Garbage Collection
Garbage Collection (GC) is the single most important factor in differentiating between these languages.
While C and C++ can be used with GC, it is a bolted-on afterthought and cannot be made to work as well (the best known is here) - it has to be "conservative" which means that it cannot collect all unused memory.
C# is designed from the ground up to work on a GC platform, with standard libraries also designed that way. It makes an absolutely fundamental difference to developer productivity that has to be experienced to be believed.
There is a belief widespread among C/C++ users that GC equates with "bad performance". But this is out-of-date folklore (even the Boehm collector on C/C++ performs much better than most people expect it to). The typical fear is of "long pauses" where the program stops so the GC can do some work. But in reality these long pauses happen with non-GC programs, because they run on top of a virtual memory system, which occasionally interrupts to move data between physical memory and disk.
There is also widespread belief that GC can be replaced with shared_ptr, but it can't; the irony is that in a multi-threaded program, shared_ptr is slower than a GC-based system.
There are environments that are so frugal that GC isn't practical - but these are increasingly rare. Cell phones typically have GC. The CLR's GC that C# typically runs on appears to be state-of-the-art.
Since adopting C# about 18 months ago I've gone through several phases of pure performance tuning with a profiler, and the GC is so efficient that it is practically invisible during the operation of the program.
GC is not a panacea, it doesn't solve all programming problems, it only really cleans up memory allocation, if you're allocating very large memory blocks then you will still need to take some care, and it is still possible to have what amounts to a memory leak in a sufficiently complex program - and yet, the effect of GC on productivity makes it a pretty close approximation to a panacea!
Undefined Behaviour
C++ is founded on the notion of undefined behaviour. That is, the language specification defines the outcome of certain narrowly defined usages of language features, and describes all other usages as causing undefined behaviour, meaning in principle that the operation could have any outcome at all (in practice this means hard-to-diagnose bugs involving apparently non-deterministic corruption of data).
Almost everything about C++ touches on undefined behaviour. Even very nice forthcoming features like lambda expressions can easily be used as convenient way to corrupt the stack (capture a local by reference, allow the lambda instance to outlive the local).
C# is founded on the principle that all possible operations should have defined behaviour. The worst that can happen is an exception is thrown. This completely changes the experience of software construction.
(There's unsafe mode, which has pointers and therefore undefined behaviour, but that is strongly discouraged for general use - think of it as analogous to embedded assembly language.)
Complexity
In terms of complexity, C++ has to be singled out, especially if we consider the very-soon-to-be standardized new version. C++ does absolutely everything it can to make itself effective, short of assuming GC, and as a result it has an awesome learning curve. The language designers excuse much of this by saying "Those features are only for library authors, not ordinary users" - but to be truly effective in any language, you need to build your code as reusable libraries. So you can't escape.
On the positive side, C++ is so complex, it's like a playground for nerds! I can assure you that you would have a lot of fun learning how it all fits together. But I can't seriously recommend it as a basis for productive new work (oh, the wasted years...) on mainstream platforms.
C keeps the language simple (simple in the sense of "the compiler is easy to write"), but this makes the coding techniques more arcane.
Note that not all new language features equate with added complexity. Some language features are described as "syntactic sugar", because they are shorthand that the compiler expands for you. This is a good way to think of a great deal of the enhancements to C# over recent years. The language standard even specifies some features by giving the translation to longhand, e.g. using statement expands into try/finally.
At one point, it was possible to think of C++ templates in the same way. But they've since become so powerful that they are now form the basis of a whole separate dimension of the language, with its own enthusiastic user communities and idioms.
Libraries
The strangest thing about C and C++ is that they don't have a standard interchangeable form of pre-compiled library. Integrating someone else's code into your project is always a little fiddly, with obscure decisions to be made about how you'll be linking to it.
Also, the standard library is extremely basic - C++ has a complete set of data structures and a way of representing strings (std::string), but that's still minimal. Is there a standard way of finding a list of files in a directory? Amazingly, no! Is there standard library support for parsing or generating XML? No. What about accessing databases? Be serious! Writing a web site back-end? Are you crazy? etc.
So you have to go hunting further afield. For XML, try Xerces. But does it use std::string to represent strings? Of course not!
And do all these third-party libraries have their own bizarre customs for naming classes and functions? You betcha!
The situation in C# couldn't be more different; the fundamentals were in place from the start, so everything inter-operates beautifully (and because the fundamentals are supplied by the CLR, there is cross-language support).
It's not all perfect; generics should have been in place from the start but wasn't, which does leave a visible scar on some older libraries; but it is usually trivial to fix this externally. Also a number of popular libraries are ported from Java, which isn't as good a fit as it first appears.
Closures (Anonymous Methods with Local Variable Capture)
Java and C are practically the last remaining mainstream languages to lack closures, and libraries can be designed and used much more neatly with them than without (this is one reason why ported Java libraries sometimes seem clunky to a C# user).
The amusing thing about C++ is that its standard library was designed as if closures were available in the language (container types, <algorithm>, <functional>). Then ten years went by, and now they're finally being added! They will have a huge impact (although, as noted above, they leak underfined behaviour).
C# and JavaScript are the most widely used languages in which closures are "idiomatically established". (The major difference between those languages being that C# is statically typed while JavaScript is dynamically typed).
Platform Support
I've put this last only because it doesn't appear to differentiate these languages as much as you might think. All these languages can run on multiple OSes and machine architectures. C is the most widely-supported, then C++, and finally C# (although C# can be used on most major platforms thanks to an open source implementation called Mono).
My experience of porting C++ programs between Windows and various Unix flavours was unpleasant. I've never tried porting anything very complex in C# to Mono, so I can't comment on that.
Other Answers
Answered Mar 28, 2009 · 15 votes
C is the bare-bones, simple, clean language that makes you do everything yourself. It doesn't hold your hand, it doesn't stop you from shooting yourself in the foot. But it has everything you need to do what you want.
C++ is C with classes added, and then a whole bunch of other things, and then some more stuff. It doesn't hold your hand, but it'll let you hold your own hand, with add-on GC, or RAII and smart-pointers. If there's something you want to accomplish, chances are there's a way to abuse the template system to give you a relatively easy syntax for it. (moreso with C++0x). This complexity also gives you the power to accidentally create a dozen instances of yourself and shoot them all in the foot.
C# is Microsoft's stab at improving on C++ and Java. Tons of syntactical features, but no where near the complexity of C++. It runs in a full managed environment, so memory management is done for you. It does let you "get dirty" and use unsafe code if you need to, but it's not the default, and you have to do some work to shoot yourself.
2/5
Top Answer
Answered Mar 25, 2018 · 2 votes
N1570 6.11.6:
The use of function declarators with empty parentheses (not prototype-format parameter type declarators) is an obsolescent feature.
This same wording appears in the 1990, 1999, and 2011 editions of the ISO C standard. There has been no change. The word obsolescent says that the feature may be removed in a future edition of the Standard, but so far the committee has not done so. (Function pointer declarations are just one of several contexts where function declarators can appear.)
The Introduction section of the C standard explains what obsolescent means:
Certain features are obsolescent, which means that they may be considered for withdrawal in future revisions of this International Standard. They are retained because of their widespread use, but their use in new implementations (for implementation features) or new programs (for language [6.11] or library features [7.31]) is discouraged.
A call to a function declared with an old-style declarator is still required to pass the correct number and type(s) of arguments (after promotion) as defined by the function's actual definition. A call with incorrect arguments has undefined behavior, which means that the compiler is not required to diagnose the error; the burden is entirely on the programmer.
This is why prototypes were introduced, so that the compiler could check correctness of arguments.
On an i386 system with GCC, “extra” arguments passed in a call to an empty-parentheses-type’d function pointer are ignored, because of how stack frames work ...
Yes, that's well within the bounds of undefined behavior. The worst symptom of undefined behavior is having the program work exactly as you expect it to. It means that you have a bug that hasn't exhibited itself yet, and it will be difficult to track it down.
You should not depend on that unless you have a very good reason to do so.
If you change
int (*fp)() = foo;-
to
int (*fp)(int) = foo;-
the compiler will diagnose the incorrect call.
3/5
Top Answer
Answered Jan 28, 2024 · 0 votes
Calling a constructor and calling a function pointer of a constructor in C++ are very similar in the sense that they are both quite impossible:
- You cannot call a constructor in C++.
- You cannot obtain a pointer to a constructor in C++.
According to the C++ spec about constructors:
Constructors have no names and cannot be called directly.
So, in C++, you do not call constructors. The language does that for you when you use the new keyword, when you declare an object on the stack, etc. The expression new MyClass() might look like a constructor invocation, and it does in fact contain a constructor invocation, and so it might be mistaken for a constructor invocation, but that's not what it is; it is a "new expression", which includes, among other things, an invocation of a constructor. But the other things are crucial: you cannot just skip them and directly invoke the constructor.
Function pointers of constructors do not exist because normally you cannot take the address of a constructor. If you examine the names exported by the DLL, and somehow figure out which name corresponds to the constructor, and use that name to obtain the entry point of that constructor from the DLL, you are cheating: you are doing something which is not normally supported by the language. As a result, you should not attempt to invoke that entry point. A constructor is only supposed to be invoked by the language.
Also according to the C++ spec:
A constructor is a special non-static member function of a class.
(Emphasis mine.)
A constructor assumes that memory has been allocated, and proceeds to initialize that memory. The language takes care of the memory allocation, but invoking the constructor directly does not. Since a constructor is non-static, it expects an uninitialized this to be passed to it, but you are not allocating any memory and you are not passing anything to the constructor. The result is exactly as expected: a crash.
And besides, think about it: the constructor could not be internally allocating the memory, because how would it work then if the object was allocated on the stack? And how would it work if the constructor was being invoked by the constructor of a derived class which presumably occupies more memory?
You can get your DLL to work by using a factory method. A factory method is a public static method which executes new ClassA() and returns the result, or declares ClassA() and returns it by value. Then, obtain the address of the factory method from the DLL, and invoke it.
4/5
Top Answer
Answered Jul 21, 2018 · 1 votes
A key must be immutable.
That is the only limitations.For example, You can use a tuple as the key if the items within tuple are immutable : (1,2)
But you can not do this ([1,2])
Read up more about immutable and mutable types to get a clear idea.
5/5
www.geeksforgeeks.org › implementation-on-map-orImplementation on Map or Dictionary Data Structure in C
www.geeksforgeeks.org › implementation-on-map-orMar 27, 2023 · The printMap function prints all the key-value pairs in the map. In the main function, we insert some key-value pairs into the map, get the value of some keys, and print the map. Here’s an example implementation of a map using arrays: C. #include <stdio.h>. #include <string.h>.
stackoverflow.com › questions › 4384359data structures - Quick Way to Implement Dictionary in C ...
stackoverflow.com › questions › 4384359Section 6.6 of The C Programming Language presents a simple dictionary (hashtable) data structure. I don't think a useful dictionary implementation could get any simpler than this. For your convenience, I reproduce the code here. struct nlist { /* table entry: */. struct nlist *next; /* next entry in chain */. char *name; /* defined name */.
Code sample
struct nlist {struct nlist *next;char *name;char *defn;};...People also ask
What are keywords in C?
- Keywords are predefined or reserved words that have special meanings to the compiler. These are part of the syntax and cannot be used as identifiers in the program. A list of keywords in C or reserved words in the C programming language are mentioned below:
Keywords in C - GeeksforGeeks
www.geeksforgeeks.org/keywords-in-c/What is a dictionary key in Python?
- Almost any type of value can be used as a dictionary key in Python. You just saw this example, where integer, float, and Boolean objects are used as keys: You can even use built-in objects like types and functions: However, there are a couple restrictions that dictionary keys must abide by.
Dictionaries in Python – Real Python
realpython.com/python-dicts/How to return a list of key-value pairs in a dictionary?
- Returns a list of key-value pairs in a dictionary. d.items() returns a list of tuples containing the key-value pairs in d. The first item in each tuple is the key, and the second item is the key’s value: Returns a list of keys in a dictionary. Returns a list of values in a dictionary.
Dictionaries in Python – Real Python
realpython.com/python-dicts/Can I create a dictionary in C?
- You can create anything you want in C. You just won't have native language support for most of it. You can create a dictionary in C, but there is no dictionary built in to the standard C library. A quick search on Google code shows that there are open-source (and generously licensed) C dictionary implementations here and here.
Do dictionaries exist in C? - Stack Overflow
stackoverflow.com/questions/9405303/do-dictionaries-exist-in-ccsc.ucdavis.edu › ~chaos › coursesPart C: Dictionaries, Arrays, Functions, and Modules - UC Davis
csc.ucdavis.edu › ~chaos › coursesPart C: Dictionaries, Arrays, Functions, Modules Mappings. Mappings store associations between a set of keys and a set of values. They can be regarded as generalizations of sequences, since sequences are a restricted kind of mapping whose keys are a range of integers. Mappings allow more general keys, though, and impose no order on their elements.
www.geeksforgeeks.org › keywords-in-cKeywords in C - GeeksforGeeks
www.geeksforgeeks.org › keywords-in-cMar 18, 2024 · Keywords are predefined or reserved words that have special meanings to the compiler. These are part of the syntax and cannot be used as identifiers in the program. A list of keywords in C or reserved words in the C programming language are mentioned below: auto. break. case. char. const. continue.
realpython.com › python-dictsDictionaries in Python – Real Python
realpython.com › python-dictsDefining a Dictionary. Dictionaries are Python’s implementation of a data structure that is more generally known as an associative array. A dictionary consists of a collection of key-value pairs. Each key-value pair maps the key to its associated value.
en.wikibooks.org › wiki › Introducing_JuliaIntroducing Julia/Dictionaries and sets - Wikibooks, open ...
en.wikibooks.org › wiki › Introducing_JuliaApr 16, 2020 · In a dictionary, keys are always unique – you can't have two keys with the same name. If you know the types of the keys and values in advance, you can (and probably should) specify them after the Dict keyword, in curly braces:
en.wikibooks.org › Language_Dictionary › CSoftware Engineers Handbook/Language Dictionary/C
en.wikibooks.org › Language_Dictionary › CJul 16, 2018 · C [edit | edit source] looking for the story of C here. Type [edit | edit source] C is a full, procedural language. Execution Entry Point [edit | edit source] An executable starts with the main() method. General Syntax [edit | edit source] The typical statement is completed by a semi-colon. For the assignment of b to a use:
Searches related to what are the function of dictionary keys in c world