Find the answer to your Linux question:
Results 1 to 4 of 4
I would like to optimize a C program ..Do you think it would be useful to use datatype as register (for frequently used variables ) rather than using it auto ...
  1. #1
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Smile C programming - register data type

    I would like to optimize a C program ..Do you think it would be useful to use
    datatype as register (for frequently used variables ) rather than using it auto?

    Have you ever implemented register in your programs?

    Ex:
    register int i;
    rather than

    auto int i ; // or just int ;
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  2. #2
    Linux Enthusiast gerard4143's Avatar
    Join Date
    Dec 2007
    Location
    Canada, Prince Edward Island
    Posts
    714
    Personally I would use inline assembler before I would use register(it gives the programmer more control)...if your interested in optimizing programs try reading up on the -O switch in gcc...Hope this helps Gerard

  3. #3
    Linux Guru Lakshmipathi's Avatar
    Join Date
    Sep 2006
    Location
    3rd rock from sun - Often seen near moon
    Posts
    1,568

    Post

    Thanks Gerard ..that's very useful suggestion. I'll try it out...
    - Lakshmipathi.G
    -------------------
    FOSS India Award winning ext3fs Undelete tool and tutorials www.giis.co.in
    First they criticize you,Then they laugh at you,Then they fight with you,Then you win. - M.K.Gandhi
    -------------------

  4. #4
    Just Joined!
    Join Date
    Jun 2010
    Posts
    1

    Data Type in Programming

    I declared a variable as int data type which was a placeholder for a result status (meaning, based on the result status that variable varies from 0/1/2/3. It can contain only these four values).

    “int” data type is 4 byte integer in C#. But I can declare this variable as “sbyte” which represents a 1 byte integer. Since that variable contains only 1 or 2 or 3 or 4, declaring the variable as “int” is wastage of memory space.

    Before declaring any variable we need to just think of the memory space needed for that variable, our requirement, any other good alternative for this variable.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...