Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 219785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:52:38+00:00 2026-05-11T18:52:38+00:00

I would like to compile the following C program for 32- and 64-bit systems.

  • 0

I would like to compile the following C program for 32- and 64-bit systems.

#include <stdio.h>                                                                                                                                                                  
#include <stdlib.h>                                                                                                                                                                 
#include <stddef.h>                                                                                                                                                                 

int main(int argc, char** argv) {
  size_t size = atoi(argv[1]);                                                                                                                                                      
  int *array;                                                                                                                                                                       

  array = malloc(size * sizeof(int));                                                                                                                                               
  if (array == NULL) {                                                                                                                                                              
    fprintf(stderr, "could not allocate memory\n");                                                                                                                                 
    exit(1);                                                                                                                                                                        
  }                                                                                                                                                                                  
  fprintf(stdout, "memory allocated on heap: %u bytes\n", sizeof(int)*size);                                                                                                        

  fprintf(stdout, "press Return to quit\n");                                                                                                                                        
  getchar();                                                                                                                                                                        

  fprintf(stdout, "freeing memory\n");                                                                                                                                              
  free(array);                                                                                                                                                                      

  exit(0);                                                                                                                                                                          
}         

What I have been doing with my Makefile is pass in -m32 and -64 to make bit-specific binaries:

CFLAGS=-ansi -pedantic -Wall -O3
32BIT_ARCH=-m32
64BIT_ARCH=-m64
32_CFLAGS=${32BIT_ARCH} ${CFLAGS}
64_CFLAGS=${64BIT_ARCH} ${CFLAGS}
CC=gcc
ARRAY_32BIT_BINARY_NAME=arrayTest32
ARRAY_64BIT_BINARY_NAME=arrayTest64

all: ${ARRAY_32BIT_BINARY_NAME} ${ARRAY_64BIT_BINARY_NAME}
arrayTest32: main32_array.o 
             ${CC} ${32_CFLAGS} main32_array.o -o ${ARRAY_32BIT_BINARY_NAME}
arrayTest64: main64_array.o
             ${CC} ${64_CFLAGS} main64_array.o -o ${ARRAY_64BIT_BINARY_NAME}
main32_array.o: main.c
             ${CC} ${32_CFLAGS} -c main.c -o main32_array.o 
main64_array.o: main.c
             ${CC} ${64_CFLAGS} -c main.c -o main64_array.o 
clean:
             -rm *.o *~ ${ARRAY_32BIT_BINARY_NAME} ${ARRAY_64BIT_BINARY_NAME}
install:
             cp ${ARRAY_32BIT_BINARY_NAME} ${ARRAY_64BIT_BINARY_NAME} ../bin

This works great, but I run into a warning when compiling:

$ make                                                                                                                                   
gcc -m32 -ansi -pedantic -Wall -O3 -c main.c -o main32_array.o                                                                                                                      
gcc -m32 -ansi -pedantic -Wall -O3 main32_array.o -o arrayTest32                                                                                                                    
gcc -m64 -ansi -pedantic -Wall -O3 -c main.c -o main64_array.o                                                                                                                      
main.c: In function ‘main’:                                                                                                                                                         
main.c:14: warning: format ‘%u’ expects type ‘unsigned int’, but argument 3 has type ‘long unsigned int’                                                                            
gcc -m64 -ansi -pedantic -Wall -O3 main64_array.o -o arrayTest64  

What I would like to do is fix this warning without having two main.c files for two “bit” targets.

Is there an #ifndef or other preprocessor conditional I can add to line 14 of main.c to handle this difference?

Or is there a different and better way to handle this?

EDIT: I used the following solution:

#if defined(__LP64__)                                                                                                                                                               
  fprintf(stdout, "memory allocated on heap: %lu bytes\n", sizeof(int)*size);                                                                                                       
#else                                                                                                                                                                               
  fprintf(stdout, "memory allocated on heap: %u bytes\n", sizeof(int)*size);                                                                                                        
#endif      
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T18:52:39+00:00Added an answer on May 11, 2026 at 6:52 pm

    See here for a similar question.

    LP64
    _LP64
    These macros are defined, with value 1, if (and only if) the
    compilation is for a target where long
    int and pointer both use 64-bits and
    int uses 32-bit.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 178k
  • Answers 178k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Setting VM argument should work: java -Duser.home=<new_location> <your_program> Here's a… May 12, 2026 at 3:42 pm
  • Editorial Team
    Editorial Team added an answer Several things to note: First, the command line you gave… May 12, 2026 at 3:42 pm
  • Editorial Team
    Editorial Team added an answer Do I need to encode strings (eg URL) I pass… May 12, 2026 at 3:42 pm

Related Questions

I'm writing an add-in for ReSharper 4. For this, I needed to reference several
I am having an issue with the Microsoft Visual Sourcesafe command line options that
In response to this question asking about hex to (raw) binary conversion, a comment
I'm creating a package that is going to be used by R (the statistical

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.