Thread: file size with binary write larger than it should be?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    - - - - - - - - oogabooga's Avatar
    Join Date
    Jan 2008
    Posts
    2,808
    Could you run this program please.
    Code:
    #include <stdio.h>
    
    int main() {
        char str[7];
        printf("%d %d %d %d\n", sizeof(char), sizeof(short),
                                sizeof(int),  sizeof(str));
        return 0;
    }
    The cost of software maintenance increases with the square of the programmer's creativity. - Robert D. Bliss

  2. #2
    Registered User
    Join Date
    Feb 2012
    Posts
    10
    Quote Originally Posted by oogabooga View Post
    Could you run this program please.
    Code:
    #include <stdio.h>
    
    int main() {
        char str[7];
        printf("%d %d %d %d\n", sizeof(char), sizeof(short),
                                sizeof(int),  sizeof(str));
        return 0;
    }
    The result of this program yields:

    1 1 1 7

    So it would seem my sizeof function does not work in the same way as most of what I have read online seems to be suggesting.
    I am compiling for a DSP Core, made by Ceva called Teaklite.

    I am thinking I should try the #pragma pack(1) just to see what the file size results will be... if they are what I expected then its packing. If not, I have 16 bit char types and need to figure out something else.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Image(bitmap) larger size than the initial
    By nutzu2010 in forum Windows Programming
    Replies: 2
    Last Post: 08-02-2011, 06:01 AM
  2. Defining Buffer size for write to file
    By catchaat in forum C Programming
    Replies: 5
    Last Post: 03-21-2011, 02:11 AM
  3. write an array of unspecified size to a file
    By c++guy in forum C++ Programming
    Replies: 3
    Last Post: 09-22-2010, 10:54 PM
  4. Write Binary File
    By doia in forum C Programming
    Replies: 14
    Last Post: 02-26-2010, 10:20 AM
  5. Need larger shmget() size.
    By endomlic in forum C Programming
    Replies: 2
    Last Post: 04-10-2009, 02:22 PM

Tags for this Thread