Undefined operations on integers in c [closed] - c

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.

Related

What can LLVM represent that C cannot? [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 3 years ago.
Improve this question
As far as I know, it is almost true that any code that can be represented in the LLVM intermediate language, can also be represented in C, with two important exceptions:
Exceptions. (No pun intended.)
Signed integer arithmetic with well-defined behavior on overflow.
Is there anything else that can be represented in LLVM but not in C?
In addition to exception handling, other big features are garbage collection and out-of-the-box coroutines. Going to a lower level, there are trampoline intrinsics, patch points for JITs, and direct support for Obj-C ARC Runtime intrinsics.
C is Turing complete, so all of these things can be introduced to C with libraries and so on, but I put them as they are part of the LLVM language.
Metadata for example, including LLVM's branch-weight and debugloc metadata.
Except that they can if you're willing to be tortuous enough about the C you write. I think that's general: IF you're willing to write really tortuous, unidiomatic C, THEN you can write anything. So I vote to close this as unclear.
EDIT: Most things probably are expressible in C given enough discipline, verbosity and preprocessing directives, but I wonder about aliasing.

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 exactly is the SEXP data type in R's C API and why is it used? [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 am aware of the wikipedia page on SEXP, and I know that it stands for symbolic expression. I know (vaguely) SEXP is notation to refer to tree data structures in Lisp, but I want to know what motivated the developers to call the data type of R objects in C SEXP. Why SEXP?
I am also confused because if R was made in C and Fortran, why would notation from Lisp be used? Or is SEXP a more general term? Maybe I'm missing something here.
R is, internally, kind of like Scheme with an S-compatible syntax. A lot of R's internals derive from Scheme concepts, like cons cells and lexical environments.
Back in the late 90s, I worked on a new (at the time) serialisation format for R; see my honours project paper, which explains a lot of this. (The email address on that paper isn't valid any more, so don't use that.)

I don't understand what he wants [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 7 years ago.
Improve this question
The question is from "The C programming language" book and it reads "Write a program to determine the ranges of char, int, short, and long variables both signed and unsigned, by printing the appropriate values from standard headers or by direct computation."
My first problem is that I don't understand how can i directly print the values from standard headers... I don't even know what they are, I think i might have missed them while reading. And my second problem is I don't understand what he means by direct computation.
sorry if its a stupid question, I'm fairly new to programming.
Right above this exercise in The C Programming Language it says:
The standard headers <limits.h> and <float.h> contain symbolic constants for all of these sizes, along with other properties of the machine and compiler. These are discussed in Appendix B.
So, see Appendix B (page 257 in the second edition I have). =)

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