sizeof operator in c [closed] - c

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
please can anybody help me to implement sizeof() operator in c..
i know the usage .. but i was not able to implement it.

You cannot implement sizeof() as a library function, it is a compiler intrinsic. Are you writing a compiler?

You can't implement sizeof in C; it's a basic operator (you can't implement + either).
You could write a macro that has a limited subset of sizeof's behavior, by doing something along the lines of:
#define thisIsAHorribleHackDontDoThis(a) \
((size_t)((intptr_t)(&a + 1) - (intptr_t)&a))
but that only works if a is an lvalue (and it's horrible to behold). sizeof is not so limited, and that's why you should use it instead of reinventing a wheel that isn't actually round.

Below is the implementation of sizeof operator
#define SZOF(x) (size_t)(((x*)(0))+1)

Related

PHP Error Undefined Functions [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I am getting Error Undefined Function.
Here is the code:
$myvar = "#file_get_contents";
eval($myvar("http://someurlupdatehere.com"));
The error I get is:
<b>Fatal error</b>: Call to undefined function #file_get_contents() ..
#file_get_contents() is not a valid PHP function. You can remove the suppression operator to make this work:
$myvar = "file_get_contents";
If you still need to use the suppression operator, do:
eval('#' . $myvar("http://someurlupdatehere.com"));
or even leave the suppression operator and pass the entire line as a string:
$myvar = "#file_get_contents";
eval("$myvar('http://someurlupdatehere.com');");
Note that the use of the suppression operator and eval is generally a bad idea.
It looks really weird to me what you are trying to do. I tend to say "Don't use eval, don't do that!" ;)
Anyway, here comes the right syntax:
$myvar = "#file_get_contents";
eval("$myvar('http://someurlupdatehere.com');");
Or if you need the return value of file_get_contents() in a variable (what is likely, use this:
$myvar = "#file_get_contents";
eval("\$file = $myvar('http://someurlupdatehere.com');");
echo $file;
<?php
$myvar = "file_get_contents";
eval(#$myvar("http://someurlupdatehere.com"));
?>
Works as well. Suppresses errors.

Is there a benefit in doing pthread_exit after pthread_join in main()? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
https://computing.llnl.gov/tutorials/pthreads/samples/join.c
Please see the code in the link above.
Is there any benefit in doing pthread_exit after pthread_join in main()?
Judging from the POSIX specification of pthread_exit(), there isn't much benefit to using pthread_exit() instead of either exit() or _exit() or return. Nominally, it means that atexit() handlers are not executed, and it might mean that file streams are not flushed — more like _exit(). In the context of the sample code, it seems unnecessary.

Bit wise or of two Unsigned Integer (Program Crashes) [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
Sorry if my problem is not very clear.
I've a structure like this:
typedef struct
{
uint32_t typeSet;
}DataTypeTagInfo;
The following function is for unifying two typeSet:
DataTypeTagInfo* unifyTagInfo(DataTypeTagInfo* tag1, DataTypeTagInfo* tag2){
if(tag1 == NULL) return tag2;
else if(tag2 == NULL) return tag1;
tag1->typeSet |= tag2->typeSet;
return tag1;
}
The program exits while executing the following line:
tag1->typeSet |= tag2->typeSet;
On a sample run I've following value:
tag1->typeSet = 3917954189
tag2->typeSet = 2536589
There is no error message. Just quits. Please help.
The code you show is perfectly sound. Consequently, it's very likely that either tag1 or tag2 is an invalid pointer at the time of the abort. This will have nothing to do with the code you've posted. The pointers could be set invalid in many, many ways.
To figure out what's happening, I'd start with a careful review of the code setting tag1 and tag2 at the call site and then - if the answer does not appear - move on to using valgrind to check for memory overwrite errors.
NB this what makes C(++) so challenging.

error expected primary-expression before 'char' [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 10 years ago.
i have a question,
i am trying this
if (strncmp(m_DSServer, "TCP:", 4) != 0 )
return DS_AS_PROCESS_NAME_INCORRECT;
if
if(strchr(char *(m_DSServer[4]),':')== NULL) //here it is giving me primary-expression before 'char
return DS_AS_PROCESS_NAME_INCORRECT;
else
if(strchr(m_DSServer[4],'/')== NULL)
return DS_AS_PROCESS_NAME_INCORRECT;
If you want to start searching from the 5. character, do
strchr(&m_DSServer[4],':')
Firstly, cast syntax that has the type(value) form is a chiefly C++ syntax. It is not supported in C. And your question is tagged [C], not [C++]. In C language you have to use the (type) value syntax when you want to perform a cast.
Secondly, even in C++ the type(value) cast syntax requires the type part to consist of a "compact" type specifier, i.e. even in C++ you can't use char * in this context.
Thirdly, regardless of the syntax you use, it is entirely not clear what you are trying to do by casting m_DSServer[4] value (which is apparently a char) to pointer type. This just does not make any sense.
If you wanted to do a search for a : character starting from the 4th position in string m_DSServer, you should do something like strchr(&m_DSServer[4], ':'). No casts necessary.
if (strchr(char *(m_DSServer[4]),':') == NULL)
^^^^^^^^^^^^^^^^^^^^^
char *(m_DSServer[4]) is nonsense. My guess is that you want to search the string for :, starting from the 4th character. In that case, you want a pointer to the 4th character:
if (strchr(m_DSServer+4,':') == NULL)
^^^^^^^^^^^^

UAL Assembly from C to UAL assembly [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 11 years ago.
Rewrite the following program in UAL assembly, given its C code. Assume that gcd()
and print() are ABI compliant functions that calculate the greatest common divider
and print the variable respectively. Make sure to annotate your assembly code
int main() {
uint32_t a=0x5, b, i;
b = 4*a;
while(i<10) {
b = gcd(a, b);
i++;
}
print(b);
}
this is for a pre-lab that i am trying to do ... thank you
This does not look like a prelab. It does however look like problem 1 (worth 20 points) that was just assigned in Embedded Systems. You should take the time to learn assembly and the equivalent in C. You will struggle in the class otherwise, since Stack Overflow wont help you on your upcoming exam.... Join a study group if you are having problems with assembly, there are other student in the class dealing with the same issues as you. There is almost always students in the lab as well.
Also, UAL is a ARM Assembly syntax see link:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0473c/BABJIHGJ.html

Resources