User Profile

Collapse

Profile Sidebar

Collapse
Aftabpasha
Aftabpasha
Last Activity: May 30 '10, 04:53 PM
Joined: Oct 20 '08
Location: India
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • toupper() function implementation using Bitwise operations --- Speed difference

    Hello,
    I was trying to implement toupper() functionality using bitwise operations (assuming only alphabets as input).
    Code:
    #include <stdio.h>
    #include <ctype.h>
    
    int main()
    {
        int i=0;
        unsigned int mask = ~32;
        char  buffer[512] = "Hello there THis IS better Than THE Best";
        
        printf("%s\n",buffer);
        
        while
    ...
    See more | Go to post

  • Aftabpasha
    replied to Pointer issue on IA-32 and IA-64
    in C
    I completely missed the 'only C' perspective of the problem. Now all doubts are cleared.
    Thank you all for their quick attention and helpful comments.

    Regards,

    Aftab.
    See more | Go to post

    Leave a comment:


  • Aftabpasha
    replied to Pointer issue on IA-32 and IA-64
    in C
    I don't think protottyping is a reason. If proper header file for malloc() is not included, then compiler would show an error message rather than trying to return an integer (default return type).

    I think Jos is right. I guess it is faulty malloc implementation that is triggering this problem. I think the things are going as described below.

    According to the C standard, malloc() always returns a suitably aligned address....
    See more | Go to post

    Leave a comment:


  • Aftabpasha
    replied to Pointer issue on IA-32 and IA-64
    in C
    But the malloc() just allocates a BLOCK OF MEMORY of specified size and returns a void pointer to it's starting address. That's why I thought the problem is some where in pointer conversion process. Just don't know where exactly it is.
    The following is the link to the puzzle
    http://www.gowrikumar.com/c/index.html

    I just saw an old discussion on the same puzzle, but I ended up with confusions. Here is the link to it...
    See more | Go to post

    Leave a comment:


  • Aftabpasha
    replied to Pre-processor query
    in C
    Thanks for fruitful reply.
    See more | Go to post

    Leave a comment:


  • Aftabpasha
    started a topic Pointer issue on IA-32 and IA-64
    in C

    Pointer issue on IA-32 and IA-64

    I've seen a puzzle while surfing. It is given below.

    I think, the problem is related to pointer type conversion. I don't have a 64-bit processor. I was unable to fully elaborate it.
    Please explain why does this program behaves differently on different architectures.
    Thanks....
    See more | Go to post

  • Aftabpasha
    replied to Pre-processor query
    in C
    Thanks for replying.
    Still I've a confusion.

    Does a C Preprocessor work in multiple passes or in a single pass?

    Thanks.
    See more | Go to post

    Leave a comment:


  • Aftabpasha
    started a topic Pre-processor query
    in C

    Pre-processor query

    I've seen the following code snippet.
    Code:
    #include <stdio.h>
    
    #define f(a,b) a##b
    #define g(a) #a
    #define h(a) g(a)
    
    int main()
    {
    printf("%s\n",h(f(1,2)));
    printf("%s\n",g(f(1,2)));
    return 0;
    }
    The output is
    Code:
    12
    f(1,2)
    I GUESS that in the first printf(), firstly, it is replacing h(f(1,2)) by...
    See more | Go to post

  • Aftabpasha
    replied to help with files and delimiters
    in C
    First read (all or part of) the file in the buffer, and then scan it till you find end of current record(delim2), or beginning of next record(i.e. delim1), or an EOF, continue this for each record/block.

    If you know the possible size of each record(block), and/or how many numbers are present in each/last block in your file then you can use it as well.
    See more | Go to post

    Leave a comment:


  • Thanks Josh for clearing my doubts.

    Kind Regards,
    Aftab
    See more | Go to post

    Leave a comment:


  • Please look at the code below.

    Code:
    int x =2;
    printf("%d, %d, %d", ++x, ++x, ++x);
    Now, by the rules, the printf statement has a potential of Undefined behavior. With a simple guess, the possible outputs are (3, 4, 5) or (5, 4, 3) (considering the two different orders of evaluation of arguments). Now, is there an such possibility of output like (4, 3, 5) or (3, 5, 4) or (5, 3, 4) or even (GARBAGE,...
    See more | Go to post

    Leave a comment:


  • Is there a sequence point at the end of a parametrized macro, just like a function?
    e.g.
    Code:
    #define SQR(x) ((x)*(x))
    So when we use SQR(10); is there a sequence point concept like function call?
    See more | Go to post

    Leave a comment:


  • Thanks Jos,

    That means, arguments of a function call are not considered as Full expressions.

    One more dumb question.

    Code:
    int i=2;
    i = ++i;'
    In the above code, the expression i = ++i; according to the standards, should be an undefined behavior. But when I try to guess different possible outcomes of this expression, I can only think of 3 (as final value of i). How can it be undefined? Please...
    See more | Go to post

    Leave a comment:


  • Sequence points while evaluating function arguments, Unspecified or Undefined behavio

    In a function call like
    Code:
    printf("%d,..",++i,++i,..)
    can we consider every ++i as a Full Expression? And if it is a full expression, it means there is a sequence point after every ++i. So, uncertainty exists only about order of evaluation of arguments and not about the side-effects of each of the ++i expressions causing Undefined behavior. I just want to know whether such function calls cause Undefined Behavior or just Unspecified...
    See more | Go to post

  • Well, I m just a beginner...and hope I'll also have some habit after 20 years (of course a good one).
    Once again thank you all for your replies.
    See more | Go to post

    Leave a comment:


  • @Banfa
    Thank you for your clear & informative replies.
    All of my confusions about those garbage values are removed now.
    The code you've provided was certainly helpful to me.
    Just a single question. It's about the code from you. Why have you used
    Code:
    int main(int argc, char *argp[])
    I mean you could have simply used
    Code:
    int main()
    in place of it.
    Is it a better practice to use such syntax?(Command Line...
    See more | Go to post

    Leave a comment:


  • @ Banfa
    Thanks for your reply.
    Now, I got this.
    1. %s is accepting character ('y') correctly, but violating memory. Hence, the LL is getting corrupted.
    2. When read as "char"(%c), due to scanf() problem, it is reading some accidentally left characters (probably '\n') as a wrong answer.

    So, the whole problem is due to scanf() leaving some data unread in buffer.
    But this accidentally left...
    See more | Go to post

    Leave a comment:


  • @Raghu
    Thanks for your reply.
    The reason given by you can satisfy the problem when we accept "ch" as "char" i.e. using %c as format specifier.

    But when we are using "%s", it is accepting 'y' properly. If there are some characters left in buffer then it should read some garbage value.in place of 'y' also.
    Here, it is accepting 'y' properly but causing the value of "temp" to...
    See more | Go to post

    Leave a comment:


  • Aftabpasha
    started a topic Garbage value reading due to buffering problem
    in C

    Garbage value reading due to buffering problem

    I have seen a simple program for handling Link List operations. The following is the part of the code that contains the problem. The code is modified but contains all necessary information regarding the problem.
    Code:
    #include<stdio.h>
    #include<stdlib.h>
    #include<conio.h>
    
    struct llist
    {
    	int val;
    	struct llist *next;
    };
    typedef llist item;
    
    void llist(item **head);
    ...
    See more | Go to post

  • Aftabpasha
    replied to sizeof operator on string(charcter array)
    in C
    Thank you both donbock and Banfa for your replies. I got the concept.
    Thank You.
    See more | Go to post

    Leave a comment:

No activity results to display
Show More
Working...