Results 1 to 6 of 6

Thread: help:C questions

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Answers
    4

    help:C questions

    1.What is the use of #pragma pack,where it is used?
    2.how many error occurs in C language ?
    3.How can I read a directory in a C program?


  2. #2
    Expert Member
    Join Date
    May 2009
    Answers
    1,374

    Re: help:C questions

    Quote Originally Posted by sarabjit View Post
    1.What is the use of #pragma pack,where it is used?
    2.how many error occurs in C language ?
    3.How can I read a directory in a C program?
    Hi sarabjith,

    1) The #pragma pack directive modifies the current alignment rule for only the members of structures whose declarations follow the directive.

    It does not affect the alignment of the structure directly, but by affecting the alignment of the members of the structure, it may affect the alignment of the overall structure according to the alignment rule.

    The #pragma pack directive causes bitfields to cross bitfield container boundaries.

    2) It depends on the code
    3)Use header file dirent.h.This .h , file contains the direcory manipulation functions like opendir,closedir,readdir.

    Regards,
    Rijus

    Real Inspirational Journey........Unanimously & Sincerely.

  3. #3
    Junior Member
    Join Date
    Feb 2010
    Answers
    1

    Re: help:C questions

    1) #pragma - this directive is used in open MP multithreading API's
    2) I wonder if even D Richie knows bout it
    3) Yes Dirent.h can be useful , get the inode no of directory ,read the struct, get inode of the files it contains


  4. #4
    Junior Member
    Join Date
    Apr 2010
    Answers
    1

    Re: help:C questions

    Hi sarabjith,

    #pragma is known as a compiler directive which helps the compiler to understand or inform about some activities such as the allignment of the bits, switching the optimisation on or off, etc.
    # pragma pack is used for bit allignment for the structure members. In 32 bit environment, in most of the cases structure padding takes place when we go for the structures in the coding, for the efficiency in speed. But, due to structure padding, the occupation of memory space will be more. If we are coding for an embedded system, we know that the memory is a constraint. Then there will be a need to utilise the memory efficiently, for example let us consider one factor that is there should be no padding.
    Now this information must be explicitly passed to the compiler that it should not perform any default padding mechanism.

    Ex: struct padding
    {
    char a;
    int b;
    }
    total bytes occupied by this structure is = 8

    #pragma pack(1) /* informing compiler to have 1 byte of allignment */

    struct padding
    {
    char a;
    int b;
    }
    total bytes occupied by this structure is : 5


  5. #5
    Expert Member
    Join Date
    May 2008
    Answers
    100

    Thumbs up Re: help:C questions

    Types of errors in c

    1.> lexical errors ccurs when we are using invalid tokens.for example in c for 32 bit processor max size of an identifier is 255.thus if we create an identifier whose length is greater then 255 then lexical error would occur.also if are using wrong keyword name for e.g mein instead of main then lexical error would be generated.

    2.>syntax errors: when using wrong syntax while writing statements.for e.g not terminating any statement with ; (semicolon) etc.

    3.>semantic errors:these errors are actually not generated but are actually the mistakes of programmer.for e.g divide by 0.

    But an important thing is that as a user we are not able to distinguish b/w errors.and assume all errors as syntactical errors.



  6. #6
    Junior Member
    Join Date
    Aug 2009
    Answers
    4

    Re: help:C questions

    Thank You all for your reply. It really helped me to upgrade my knowledge.


  7.  Sponsored Ads
    Ad


     

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact