User Profile

Collapse

Profile Sidebar

Collapse
gsi
gsi
Last Activity: Jul 29 '08, 01:25 AM
Joined: Jul 21 '07
Location: NewYork
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • gsi
    replied to memcpy() & memmove()
    in C
    Jos,
    Thanks for the explanation.

    Regards,
    Gsi.
    See more | Go to post

    Leave a comment:


  • gsi
    replied to memcpy() & memmove()
    in C
    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....
    See more | Go to post

    Leave a comment:


  • gsi
    started a topic memcpy() & memmove()
    in C

    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.
    See more | Go to post

  • gsi
    replied to recursion
    in C
    Thanks guys for the info.

    Gsi.
    See more | Go to post

    Leave a comment:


  • gsi
    replied to recursion
    in C
    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.
    See more | Go to post

    Leave a comment:


  • gsi
    replied to c structure
    in C
    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)...
    See more | Go to post

    Leave a comment:


  • gsi
    replied to c structure
    in C
    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....
    See more | Go to post

    Leave a comment:


  • gsi
    replied to c structure
    in C
    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...
    See more | Go to post

    Leave a comment:


  • gsi
    replied to Writing a function to find even numbers
    in C
    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.
    See more | Go to post

    Leave a comment:


  • gsi
    started a topic c structure
    in C

    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...
    See more | Go to post

  • gsi
    replied to static pointer to a class intialization
    in C
    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.
    See more | Go to post

    Leave a comment:


  • gsi
    replied to Question regarding malloc
    in C
    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...
    See more | Go to post

    Leave a comment:


  • gsi
    started a topic static pointer to a class intialization
    in C

    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";}
    };

    ...
    See more | Go to post

  • gsi
    replied to passing data in C without returning.
    in C
    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....
    See more | Go to post
    Last edited by JosAH; Oct 7 '07, 02:08 PM. Reason: fixed the [code] tags

    Leave a comment:


  • gsi
    replied to question on two lines of code
    in C
    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...
    See more | Go to post

    Leave a comment:


  • gsi
    replied to Dynamic memory allocation.
    in C
    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]

    ...
    See more | Go to post

    Leave a comment:


  • gsi
    replied to Dynamic memory allocation.
    in C
    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.
    See more | Go to post

    Leave a comment:


  • gsi
    started a topic Dynamic memory allocation.
    in C

    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);
    ...
    See more | Go to post

  • gsi
    replied to C Neophyte needs guidance to String/Char processing
    in C
    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...
    See more | Go to post

    Leave a comment:


  • gsi
    replied to Recursive Function Trouble
    in C
    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.
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...