What does the following c code do? [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 7 years ago.
Improve this question
#define SRC_ASCLIN_ASCLIN0_RX (*(volatile Ifx_SRC_SRCR*)0xF0038084u)
Here SRC_ASCLIN_ASCLIN0_RX means ASCLIN(Async/Sync serial LIN Comm) Receive Service Request.
I know that the macro is used to point at the address 0xF0038084u. But I want real time examples.
Am working on UART development on Infineon microcontroller.

The macro, when expanded by the preprocessor, cast the integer literal as an address, a pointer to Ifx_SRC_SRCR, then dereferences the pointer so you can get or set the value of the memory stored at that specific address.
So you could write e.g.
Ifx_SRC_SRCR value = SRC_ASCLIN_ASCLIN0_RX;
or
SRC_ASCLIN_ASCLIN0_RX = some_other_value;
It basically equivalent to doing e.g.
int an_integer = 6;
int *pointer_to_an_integer = &an_integer;
*pointer_to_an_integer = 10; // Equivalent to SRC_ASCLIN_ASCLIN0_RX = some_other_value above

Related

assign zero to item in char array [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 9 months ago.
Improve this question
I have some materials showing this code. what does code means by making these assignments?
char inputfilename[128];
inputfilename[0] = 0;
char *argv[128];
*argv[1] = 0;
In C, character arrays are terminated by a null character (value 0). In both cases in your example, the code initializes the strings to "empty" (with a terminator in the first element). This would prove useful in any subsequent string operations (strcat, strcpy, etc.).

Pointers in C: Is cell=&num equivalent to *cell=num? [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
Suppose you have the variable int num and the pointer int* cell. Does it make a difference for the values stored in cell and num to write cell = &num or *cell = num?
cell = &num
means that the contents/value of cell will be equal to the address of num.
*cell = num
means that the content at the address stored in cell, that is the value to which the pointer is pointing to, will be equal to the value of num.

Convert string of macro to macro [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
How can a string like "EINVAL" be converted into EINVAL?
I have to convert a lot of macro string to their value, what can be done?
Here is the simplest method I can think of:
#include <errno.h>
if (!strcmp(str, "EINVAL"))
value = EINVAL;
No preprocessor trick can convert the string literal to the corresponding symbol.
But you can use the preprocessor to simplify a sequence of such tests:
value = 0;
#define conv(s) do { if (!strcmp(str, #s)) value = s; } while (0)
conv(EINVAL);
conv(ENOMEM);
conv(ERANGE);
conv(EINTR);
#undef conv
A usual, be careful with the preprocessor...

Regarding casting -1 to size_t leading to a stuck loop [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 9 years ago.
Improve this question
an interview question on glassdoor is as follows. With my knowledge, it is hard to deduce anything out of it. What could be an appropriate question?
A macro that computes a size_t number. Putting in a loop, it casts -1
to a size_t number, making the loop impossible to start.
as suggested by Michael Aaron Safyan, following might be the case
operates in the reverse:
for (size_t i = 0; i > ((size_t) -1); i--) {}
For explanation see the answer
The issue is that size_t is unsigned, so casting -1 to it will produce the maximum-valued size_t. One would fix this case by using a signed type (such as int or ssize_t).

Create data type with malloc() [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 9 years ago.
Improve this question
In C I wish to create a data type (like int or float) that has only 1byte. How can I possible do this? I've tried with malloc() but didn't work that way I tried.
Could you please give me a hand here?
Example:
sizeof(int) = 4 bytes
sizeof(char) = 1 byte
sizeof(float) = 4 bytes
sizeof(myDataType) = 1 byte
There is such data type. char is always guaranteed to be one byte long. If you want another name for that type, just use typedef and create a new type based on char.
More detailed explanation can be found in this question: Are there machines, where sizeof(char) != 1, or at least CHAR_BIT > 8?

Resources