Fastest C conditions execution [closed] - c

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 9 years ago.
Improve this question
Today I stumbled upon one simple part of code and I would like to know more people opinion.
What would be the fastest code to evaluate this graph

There is no such thing as the fastest code to evaluate this graph. It depends on the processor architecture. What can be faster on one architecture, will be slower on another, or not even possible.
Nowadays, the compilers excel at block optimizations, and you should write the code as natural as you can and let the compiler decide what "the fastest" means. If the compiler doesn't have an optimization option, the best way to handle this type of conditions is to use 'conditional move' instructions, because they do not stall the pipeline, but this is very much specific to certain architectures.

Related

Undefined operations on integers in c [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 5 years ago.
Improve this question
I am trying to learn about integer representations in c and I am having a lot of difficulty understand the fact that some operations are undefined meaning they are inconsistent among systems. I find a lot of sources claiming to teach about how these things work sometimes slip in things that are specific to the architecture they are coding for.
When I am coding I intend never to rely on undefined behaviors that happen to work a certain way on most processors.
What is the definitive truth of what happens in c (across all systems) when things like truncation, extension, comparison are done and when unsigned and signed types are included in casting and arithmetic. Which of these operations have a defined behavior across all systems?
The definitive truth is the C standard. Links to versions of it are in this answer.

different execution time or the same with different options? [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
If i compile a C program with different options like '-o, -o2, -o3' Will there be any difference in the execution time or memory utilization?.
Maybe.
Depends. You're telling the compiler to spend a bit of additional time into looking for places where it could probably optimize the code from the standard approach. It might find such places, but it also might not. On all but the most trivial programs, there is, however, quite a high probability the compiler will be able to optimize ("Hello World" doesn't optimize very well, though...).

Can Endianess of system be changed using c code [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
I know that endianess little or big is inherent to the system. Then, how is it possible to change using c code, as I have seen a code, which says it can change the endianess.
Endianess depends on the CPU hardware. So normally you can't do anything about it.
The code you have seen was most likely just tossing bytes around from one endianess to the other. Though some CPUs (for example some PowerPC) do have the possibility to configure endianess by writes to a hardware register.
You can't change the endianness of the system in general (there are bi-endian architectures), this would require you to change the instruction set. You can change the endianness of the data you use though. Take a look at this question to see how.

When is it possible to replace a function in C with a macro? [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 7 years ago.
Improve this question
As part of an assignment I was asked to implement a list of simple functions in C and whenever possible replace those functions with a macro for runtime efficiency reasons.
Is there a general rule that helps me identify if I can replace a simple function in C with a macro? And why exactly does this replacement optimise runtime efficiency?
Thank you for your time.
EDIT: As it has been pointed out by many voices here, the goal of this assignment is counter productive concerning quality of code and even efficiency in some cases.
The only general rule is: avoid function-like macros as far as possible, because they are often unreadable and/or unsafe. You should always use a function when you can.
Function-like macros usually only make sense when dealing with compile-time issues such as constants, identifiers, declarations etc.
Replacing functions with macros for the sake of performance is not something you should even consider. It once was, some 20 years ago, because then compilers were so horrible at optimizing code that programmers did that job better than the compilers. Nowadays it is the other way, leave such things to the compiler.

A byte has 8-bits. Can it be larger in another system? give an example [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 8 years ago.
Improve this question
A byte has 8-bits. Can it be larger in another system? Give an example.
Also, how many different types of calls such as writeint,writedec,writestring,writechar are there in assembly language.
Thanks.
Not any more. There was a time, yes, when there were systems without a fundamental 8-bit byte.
System where 1 byte != 8 bit?
how many different types of call such as writeint,writedec,writestring,writechar are there in assembly language
This question makes no sense. Assembly language is just a means of writing code that translates directly to machine instructions. call is just one of these instructions - it jumps to some other section of code, with the intent of returning to the place where the call was made.
The things you're referring to sound more like library routines - in which case there are any number of them, depending on the programming environment.

Resources