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

  • SEARCH
  • Home
  • 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 7707439
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:21:37+00:00 2026-06-01T00:21:37+00:00

With gcc (and possibly other compilers as well) it’s possible to define a macro

  • 0

With gcc (and possibly other compilers as well) it’s possible to define a macro outside the source file like so:

c:\MinGW\bin\gcc.exe -DDEFINED_INT=45 foo.c -o foo.exe

This will define DEFINED_INT to 45 which can be seen when compiling

#include <stdio.h>

int main() {
  printf("The define was: %d\n", DEFINED_INT);

  return 0;
}

The compiled foo.exe will then print 45 when executed.

Now, what I have no clue of is how do I pass a quoted string instead of an int. So, the printf would then be something like

  printf("The define was: %s\n", DEFINED_STRING);

and the compilation like so:

c:\MinGW\bin\gcc.exe -DDEFINED_STRING="foo bar baz" foo.c -o foo.exe

but this doesn’t work, the respective line will be

printf("The define was: %s\n", foo bar baz);

(that is: without the desired quotes).

c:\MinGW\bin\gcc.exe -DDEFINED_STRING=\"foo bar baz\" foo.c -o foo.exe

doesn’t work, neither, as gcc now tries to find the files bar and baz (the error message is:

gcc.exe: bar: No such file or directory
gcc.exe: baz": Invalid argument
<command-line>:0:16: warning: missing terminating " character

So, how can I get the compiler along with cmd.exe to do what I want?

  • 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-06-01T00:21:39+00:00Added an answer on June 1, 2026 at 12:21 am

    What’s wrong with

    -DDEFINED_STRING="\"foo bar baz\""
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to bring GCC into an infinite loop by inputting strange source
Possible Duplicate: Best compiler warning level for C/C++ compilers? GCC has thousands of options
Is it possible for gcc to link against a library that was created with
Is it possible to install gcc in iPhone (3.0 or above) with out jailbreaking
I'm running Solaris, so it's possible that this is specific to running GCC on
GCC is a very well respected multi-language compiler (from what I've gathered). One thing
gcc 4.4.2 c89 I have a wave file: 8000 Hz 16 bit I am
I'm interested in solutions for the question below for Linux and Windows, GCC, MinGW,
I'd like to install gcc to Mac OS X Leopard, and compile some software
I would like to port an existing Linux application from its plain C/C++ source

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.