Jos,
Thanks for the explanation.
Regards,
Gsi.
User Profile
Collapse
-
Jos,
That's where I am confused about , I could'nt make out why the instruction could not handle overlapping areas. I mean what it does to copy the memory right way without reversing the order of copy.
Thanks in advance,
Gsi....Leave a comment:
-
memcpy() & memmove()
Hi all,
memmove() is guranteed to work correctly if the objects overlap, I am not sure why this can't be done without any extra condition check in code for the memmove() implementation or why would memcpy() fail in this situation. Please advice.
Thanks in advance,
Gsi. -
Hi Jos,
This question is a bit irrelevant to the OP's post but just curious, the Ackermann function that you have posted is supposed to return the result when m is towered n times exponentially ....(i.e ) for Ack(3,3) the result should be 3 raised to 3 raised to 3 ? . Please advice.
thanks in advance,
Gsi.Leave a comment:
-
Hi,
I suppose the offsetof() function macro extended to c++ is restricted only for "pod types" in which classes, more or less corresponds to the C concept of struct . I guess the previous versions of g++ did not have a c++ compliant macro defined, which pulled in the C compliant macro from <stddef.h> resulting in compile time errors. Recent g++ has it specialized for c++(using conditional preprocessors)...Leave a comment:
-
Diab Coldfire compiler
#define offsetof(s,memb ) ((size_t)((char *)&((s *)0)->memb-(char *)0))
Didn't look at the compiler documentation though, I am assuming the null pointer for this implementation is not all bits zero. Please advice.
Thanks,
Gsi....Leave a comment:
-
Hi all,
Yes I was referring to what banfa said at the first place, a pointer to any member to any structure and thanks for the response.
Just curious, If the null pointer in an implementation is not all bits zero, is it that the same is achieved via pointer arithmetic (may be the difference between the member and the start of structure, assuming machine is byte addressable and pointer converted...Leave a comment:
-
Hi,
Your program indeed return's a garbage to the start up routine , since main() doesn't return a value. Regarding the expected output , the result is returned in to the variable answer in the line,
answer=is_even( number);
you have to print out the answer to stdout to view the result, say printf("%d",ans wer);
Hope this helps,
Thanks,
Gsi.Leave a comment:
-
c structure
Hi all,
I read the below question in a blog, and I am not sure if a portable way to do the same exists, or even a way to do this in C.
A function accepts an address of a structure member (not necessarily the first member) as its only argument. Given this is there a way to find out the start address of this structure object in memory. Assuming the hardware supports non aligned reads (implementation not important) and the... -
Hi AHMEDYO ,
Thanks for the reply. I was wondering how the static pointer ptr2 gets binded to the the static function print(), even though explicitly initialized to NULL at global scope. Is it that linker takes care of this implicitly.
Thanks,
gsi.Leave a comment:
-
Hi,
double *ptr = (double *) malloc(100 * sizeof(double *));
may be syntactically correct, but semantically wrong. It may be right , but it is thoroughly implementation defined. Because in this context if this is going to be right on a given implementation , then the size of a double is equal to the size of a pointer in that implementation.
int *ptr = (int*) malloc(100 * sizeof(int*)); --> this may...Leave a comment:
-
static pointer to a class intialization
Hi all,
I am a bit confused in the way the compiler handles the initialization of the static pointer ptr2 in the following code. ptr2 is explicitly intialized to NULL but still the runtime behaviour is same as ptr1.
[code=cpp]
#include<iostre am>
class stat{
public:
static void print(){std::co ut<<"Hello\n";}
};
... -
Hi,
C uses strictly pass by value. Do some thing like,
[code=cpp]
void func(int *a){ // a declared to be a pointer variable.
*a = 100;
}
int main(){
int a = 10;
func(&a); // Pass the address of variable
printf("%d",a); // Prints out 100.
return 0;
}
[/code]
Thanks,
gsi....Leave a comment:
-
Hi,
size_t is defined in <cstddef>. It is typically used to represent size in bytes, so defined as an unsigned integral type. This is preferred over 'int' data type bcos of the bigger values it can represent (Unsigned).
string::npos is a static member constant which is of 'unsigned' integral type. It is assigned a value of ' -1' . hence it wraps around to give you the maximum value that could be represented using...Leave a comment:
-
Hi,
[QUOTE : Weaknessforcats]You can't free unless you are certain no copies of the address in the pointer are tucked away in the program somewhere.[/QUOTE]
[QUOTE ilikepython]
When you free a pointer you are freeing the memory allocated at the location in which the pointer points. So you are freeing the same memory you allocated in the function because you preserved the address.[/QUOTE]
...Leave a comment:
-
Hi,
Thanks for the quick reply. Since I am freeing a copy of pointer, but eventually it is the same in value context, is it the same as freeing the original pointer ?.
Thanks in advance,
Gsi.Leave a comment:
-
Dynamic memory allocation.
HI,
I am not sure whether this code is legal... Its works fine, but I am afraid that this is not a valid thing to be done. I am freeing the returned dynamically allocated memory in the main function. In the following code below, Is the freeing of memory in either of the functions is the same, or else there is a memory leak?.
[code=c]
char * foo(void){
char *a = (char*)malloc(s izeof(char)*2);
... -
Hi ,
The program's result is undefined. A local pointer is returned(Arrays are implicitly passed and returned as pointers in c). Hence on scope exit, the pointer is no longer a valid address in memory. In line 9, q may still have 'H' in it, if no other activation record has been pushed on to the stack.
One way of doing this is to create an array (Either heap or stack) from main, pass that to the function , do a strcpy on...Leave a comment:
-
Hi,
It should be return(powerof3 (n)); in line 9. A function returning bool returns false by default, if return value is not specified (May be implementation defined).
Thanks,
gsi.Leave a comment:
No activity results to display
Show More
Leave a comment: