C++ preprocessor directive to identify OSX

I'm writing a cross platform console application. It already runs on Windows, Linux (all distros), Unix, and OSX. There is one system call in the code to clear the screen. Linux, Unix, and OSX use "clear" to clear the screen, while Windows (at the console level) uses "cls".
While it is a trivial problem to change a macro each time I compile for a different platform, it would be nice to have a preprocessor directive do this for me. Can anyone help out here? What preprocessor directive would I use to identify that I'm compiling on/for OSX?
Thanks.

It depends. WIN32 is probably going to be defined. MSC_VER is probably going to be defined too. Check for your documentation for your Windows compiler. I am hedging my answer a bit because the answer depends on what compiler you are using. If you are using GCC, then you may not have those symbols defined. But, if you are using GCC on Windows then you probably have this problem to begin with.
A better approach would be to write a "clear()" function for Windows that calls "cls". Then, your application doesn't need any OS identification. You would put the "clear()" function and all other Windows-specific code into a glue.c source file that is only linked into the Windows version.
A good goal to aim for is to make your core application logic independent of any operating system. Each build system for each OS would have a set of ancillary files (like the glue.c source) that enables it to build for that OS. You want to keep that ancillary set of files as small as possible. If you have a console application, that should be easy. Code to the curses library and install some Windows curses port.

Similar Messages

  • How to use preprocessor directives as in C?

    I have a list of id's and corresponding names associated with them,i want to map the id's to the names during the first time program runs and to use the names after that instead of id's during run time(but not mapping the id to the name again and again during runtime,only once during the start of the program, something like preprocessor directives in c ) can this be done in labview.

    Hi Amit,
          A G implementation of "#define" seems to imply pre-compile graphical substitutions - that would be interesting.  Of course it's not supported and a work-around seems necessary.  I began reading this thread with the same enthusiasm for Enums as tst, and Falkpl, but at this point Enums seem unsatisfactory, expecially in light of your criteria of "not mapping the id to the name again and again during runtime,only once during the start of the program" (that seems to rule-out falkpl's #define VI, but what about tst's idea of parsing the enum's string-representation?)
          In "C", instead of the #define, one might accomplish the very same effect (maintaing values in one place) with [global] constants.  LabVIEW has constants too - they can be defined in one place and wired to wherever they're used - why not do that?  Are you trying to achieve a specific "look" or "effect" on the diagram?
    Cheers.
    const int a = 50;
    const int b = 10;
    int main()
       int ch;
      while(1)
       scanf("%d",&ch);
       switch(ch)
         case a: printf("Hiiiii");
         break;
         case b: printf("Hello");
         break;
         default:
    Message Edited by tbd on 01-28-2008 01:10 AM
    "Inside every large program is a small program struggling to get out." (attributed to Tony Hoare)

  • Jshint flags preprocessor directives

    Hi,
    I'm trying to be good and lint my scripts, but I can't get jshint to ignore preprocessor directives, eg
    #target indesign
    #include "externalFile.jsx"
    After a bit of digging I found that you can tell jshint to ignore warnings by placing your code between:
    /* jshint ignore:start */
    code goes here
    /* jshint ignore:end */
    Unfortunately, this only works for warnings (W### warning code) but not for errors (E### error code), which preprocessor directives fall under.
    So if you're using jshint, are you able to get it to ignore error codes?
    Any advice greatly appreciated.
    John

    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • Preprocessor Directives

    We need preprocessor directives. Differentiation between
    Debug & Release builds would make life a lot easier.
    #define
    #ifdef
    #ifndef
    etc...

    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • Flex 3 vs Flex 4 Preprocessor directives and code behind (External Actionscript file)

    I have a framework that I've built that I want to use on Flex3 and Flex4.
    I've added pre-processor directives as per this link (http://livedocs.adobe.com/flex/3/html/help.html?content=compilers_21.html) and got my Flex 4 code to compile nicely.
    I then went to flex 3 and discovered my sub-class of Application wouldn't compile because it was based off of spark. No problem, I'll add in a directive.
    Except now my overridden class has duplicate code, specific to which SDK it is using.
    No problem, I'll put all of the application class code in an Actionscript file and include it in both Application class declarations for each directive.
    It works nicely in Flex 3, so I went to Flex 4, tried to compile and now I'm getting compiler errors saying things such as "The (private|public|protected) attribute may only be used on class property definitions." and "The (private|public|protected) attribute can only be used inside a package.
    This same file works in Flex 3, but not in Flex 4.
    What can I do to make the code compile in both places?
    I'll work on a simple case so I can upload some code.

    Nevermind.
    I got around this issue by renaming my sub-classed Application to "...Application".
    Now I can use a directive to specify an import statement for the extends Application portion rather than specifiing the fully qualified spark.components.Application or mx.core.Application.
    Lame - but done.

  • Can I access the photos on my iPhone directly in the OSX Lion Finder

    If I have a hundred or so photos on my iPhone that I'd like to delete, its a real pain to have to select them all one by one then delete them.
    The problem is even worse on the iPad where I recently backed up 1,100 photos from my camera ( a seemingly ideal application for the iPad) in about 30 events.  You can't simply select an event and delete it.  You have to manually select each individual photo, then delete the selected photos.
    If I could access the photos in the Lion Finder, I could SelectAll, then delete them.
    I understood that there were application that could do this, but they don't run on Lion.
    iPhone 4
    iMac running OSX LIon

    Your productname may be iPhone, but this forumname is iWeb.
    The iPhone forum is probably a better place to ask.
    This is the best positive response I can think of.

  • Beside preprocessor directives, what does # mean in C?

    I'm looking through the FFmpeg source code, and here's an example of what they're doing:
    #define REGISTER_MUXER(X,x) { \
        extern AVOutputFormat x##_muxer; \
        if(CONFIG_##X##_MUXER) av_register_output_format(&x##_muxer); }
    #define REGISTER_DEMUXER(X,x) { \
        extern AVInputFormat x##_demuxer; \
        if(CONFIG_##X##_DEMUXER) av_register_input_format(&x##_demuxer); }
    #define REGISTER_MUXDEMUX(X,x)  REGISTER_MUXER(X,x); REGISTER_DEMUXER(X,x)
    #define REGISTER_PROTOCOL(X,x) { \
        extern URLProtocol x##_protocol; \
        if(CONFIG_##X##_PROTOCOL) av_register_protocol2(&x##_protocol, sizeof(x##_protocol)); }
    x##_muxer, x##_demuxer, and x##_protocol don't look like they should be valid variable names. So why are they allowed here?

    It's valid preprocessor. the ## operator does concatenation.
    http://www.iso-9899.info/wiki/Snippets#Preprocessor

  • Direct Connection Between OSX and Ubuntu (Jaunty)

    Hello:
    I Bought my MacBook a few weeks ago and i want to transfer some information from my pc, which runs Ubuntu Jaunty. What should i do?
    Thank you

    Jarojasag wrote:
    Hello:
    I Bought my MacBook a few weeks ago and i want to transfer some information from my pc, which runs Ubuntu Jaunty. What should i do?
    yo can do it via an external drive formatted FAT so both systems can read and write to it. or yo can use file sharing and connect the computers via smb or afp.
    they need to be on the same local network. don't know how file sharing works in Ubuntu but on a Mac you need to go to system preferences->sharing and enable file sharing.
    Thank you

  • How to use preprocess​or directives (#define) in C++ header file with LabVIEW 8.2

    I have a C++ header file that contains around 2000 preprocessor directives:
    #define MEM_1   0xC
    #define MEM_2   0xD
    #define MEM_3   0x18
    I want to be able to "access" these memory offsets by identifier name (MEM_1) in my LabVIEW program like I would in a C++ program.  I do not want the overhead of parsing through the header file and storing all the offsets into an array or similar structure. 
    I've written a simple Win32 console program to return the memory offset given the identifier (see code below), and created a DLL to use with my LabVIEW program.  In the console program, you notice that I can call a function and pass in the identifer name, and get the offset back correctly:
    getOffset(MEM_1);
    In LabVIEW, I was hoping to be able to pass in the identifier (MEM_1) but was unsure what datatype to use.  In my C++ code, I defined the parameter as an int.  But in LabVIEW, I can't enter in MEM_1 as an int.   Can someone advise on how to do this?  Or if there is an alternate way to use #define's from external code inside LabVIEW?
    #include "stdafx.h"
    #include "scrmem.h"
    #include "stdio.h"
    void getOffset (int var);
    int _tmain(int argc, _TCHAR* argv[])
     getOffset(MEM_1);
    canf("%d");
     return 0;
    void getOffset (int var)
     printf("The address of MEM_1 is %x", var); 

    kaycea114 wrote:
    Hi,
    Where do you think I should use the string? 
    The way that getOffset is currently defined in the DLL, I have to connect an integer input into the LabVIEW function.  This prevents me from entering in: MEM_1 as the input to the LabVIEW function.
    Are you suggesting that I change getOffset to receive a String parameter ("MEM_1")?  Does that mean I need to do a string compare (line by line) through the header file to get the offset?  It seems like doing this search through the header file would degrade performance, but if that's the only work around, then I'll do it.
    Please advise.
    Well, what you want to do is indeed entering a string and getting back the assigned integer. That is what the C preprocessor is doing too although there it is done only once at the preprocessor stage of course and not at runtime anymore. But LabVIEW is not a C preprocessor.
    What you did so far seems to be to define getOffset() that accepts an enum that needs to be created from the C source code to then return the assigned constant. That's of course not very helpful.
    And writing a VI that could parse the C header file and create a name/constant array is really a lot easier than doing the same in C. You don't even need to parse the file each time again, but can instead cache them in an uninitialized shift register (LV2 style global).
    Even more easy would be to create from that data a ring control using property nodes and save it as custom control and voila you have the most direct lookup you can get in LabVIEW and it works just as comfortable as using the define in C code. It would mean that you need to seperate your header file possibly into several different files to only get related constants into the same ring control, but that is easily done.
    Rolf Kalbermatter
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • TS5293 How to Have Multiple Devices on Maps osX with different iCloud accounts?

    I would like to be able to send my girlfriend directions thru the osX Maps app.  I know and always will know all her icloud info and password but i would wanna keep our icloud accounts seperate.
    Any suggestions on how to do this?

    I haven't tried this but im sure it will work.
    It just seems like there must be an easier way.  Instead of me having to log out of my account, log in to another account to be able to send her directions from the MAP app.
    If I tried to just log out of my icloud account on my profile it prompts me that everything will be deleted so i am not able to go that rout.
    Anyway's I will do it as you suggested unless something else comes up.
    Thanks

  • Saving pdf on network drive from OSX results in damaged pdf

    Hi,
    I've noticed something weird.
    My gf needs pdf's with forms, so the default preview app that comes with OSX does not suffice.
    So I downloaded the latest version of Adobe Reader for OSX and she was happy to change the pdf's.
    However later I found out that all the files were corrupted. The thing is like this.
    The files are on a NAS device (normally copied form a linux boxed by rsync (thus via ssh).
    The linux box had issues so she manipulated the pdf's directly on the NAS from an osx machine (using Adobe Reader).
    The OSX machine displays the NAS drive fine, so you can navigate to the correct folder and open the pdf. But after saving the time stamp is not changed.
    I saw that it created a hidden file of the original pdf of about 10% of the original size. This file cannot be opened or (damaged or corrupted message). I tried to fix / merge it with pdftk but that did not help (I later saw that pdftk is rather old).
    However if I save the file directly on the OSX drive it is fine.
    To rule things out I changed another file type (.xls) with openoffice and saved it directly on the NAS, this went fine.
    Could this be a weird bug in Adobe Reader (as AR corrupts the file on the NAS and openoffice deals with storing a remote file correctly) or might it be something else?
    Alex

    Check this:
    Error while saving a .PDF File to a mapped drive

  • Ho do I import .iMovieTrailer file to iMovie for OSX

    Hiya,
    With the recent update for iMovie for iOS including more trailer styles, I have created a trailer on my iPad which I would love to edit using iMovie for OSX. So I have a bit more control and fine tuning over the trailer.
    Currently the 'Scary' themed trailer is not available directly in the OSX version. Hence me starting on an iPad in the hope I can export it into the OSX version.
    With a project or trailer I can press the Share to iTunes options which makes it available for me to save the project/trailer files to my desktop.
    If the iMovie is a project it can be opened in the OSX version using the File --> Import --> iMovie for iOS Project
    However I tried the same menu option for the trailer file and it does not work.
    So a a project with the file extension .iMovieMobile is able to be imported but a trailer with the extension .iMovieTrailer can't.
    Has anyone managed to import a trailer, if so I would love to hear how you do it.
    Cheers,
    Warren

    Hiya Thanks for that,
    I have just submitted this as a suggestion using that link you sent me.
    I suppose if anyone else comes across this thread, please do the following:
    Mark the top item in the thread as 'I have this question too'
    And submit the problem/issue as a suggestion to Apple using the form at http://www.apple.com/feedback/imovie.html
    The more that Apple are made of aware of the issue/feature request the more likely it will get some attention.
    Cheers,
    Warren

  • Please HELP! = major disk issue - none of OSX "help" tools works (repair/time machine/reinstall)

    Hello to all,
    My first post, but directly with a very difficult case I suddenly encountered yesterday evening...
    When, as usually I opened the lid, it turned on from sleep, as usually, however frozen suddenly... so I did hard turn off... with ON/OFF button. When it turned on again, I had no possibility to put my password, but I was directly faced with "OSX tools" with 4 options (it is in Polish so I try the translation):
    1) Recover from Time Machine back up;
    2) Install OSX again;
    3) Get online help;
    4) Disk tool;
    I am totally ****** off how this could happen. There was so much stuff on the disk, including the whole Aperture libary with thousends of my daughter photos (she was born a year ago) - priceless stuff.
    I would never expect Apple to give me such an "experience"... never heppened to me on any PC's before..
    I have 2011 MacBook Pro 13" with Maverics.
    This is what I encountered using each of solutions:
    1) I use Synology DS209 for Time Machine backup (connected via Lan cable). As far as I remember backup is about 2 months old. Anyway when I choose this option. OSX tool finds the Time Machine in DiskStation, connects to "MacBook Pro" timemachine on the external disk, BUT cannot find any BACKUP further on!!!! I am lost!
    2) second, but not preferred option is OSX reinstallation.After initial analysis, and conditions acceptance, I cannot choose the only disk available. I can see only "recovery disk", but when I click on it, there is a message popping up "This disk is blocked". Obviously this prevents any further activities in reinstallation;
    3) Third option is BS clearly, no help at all.
    4) Disk tool shows me several disks / I am not an expert, so I am not sure how to understand it (Bold is active, standard non active):
    - 320,07 GB Hitach HTS54503...
         - Macintosh HD
    - Superdrive
    - disk1
         - OS X Base System
    I run "check disk" for Hitachi. No problems. Nothing to repair.
    I run "check disk" for Macintosh HD => This disk requires repair. So I run "repair". Quickly I get a message "Disk Tool is unable to repair this disk. Please backup as much data as possible, format the disk and recover the files from backup"..... Really????? How can I backup any files???
    DEAR COMMUNITY, please HELP!
    What to do in order not to loose any data on one hand and on the other be able to use the computer again?
    Please note I do not use "recovery CD" all is running without anything in CD/DVD drive.
    Thanks in advance for your answers, competence and experience!
    Disk tool does not give any solution, showing

    You are in a bad situation, because the internal drive has malfunctioned and your only backup is on a device that is not suitable for use with Time Machine, despite what its manufacturer says.
    You must try to make another backup now, before you do anything else. It may or may not be possible.
    There are several ways to back up a Mac that is not fully functional. You need an external hard drive to hold the backup data.
    1. Boot from the Recovery partition or from a local Time Machine backup volume (option key at startup.) Launch Disk Utility and follow the instructions in this support article, under “Instructions for backing up to an external hard disk via Disk Utility.”
    2. If you have access to a working Mac, and both it and the non-working Mac have FireWire or Thunderbolt ports, boot the non-working Mac in target disk mode. Use the working Mac to copy the data to another drive. This technique won't work with USB, Ethernet, Wi-Fi, or Bluetooth.
    3. If the internal drive of the non-working Mac is user-replaceable, remove it and mount it in an external enclosure or drive dock. Use another Mac to copy the data.

  • Quick C preprocessor format question

    Really 2 questions. I want to use the same macro name to generate a list of fields, a list of method declarations and the code for the needed methods. What I am not sure about is (1) how to enclose a parameter to the macro so it will appear in a string in one definition, and (2) as part of a concatenated method name.
    My example#define name(par1,par2) -(void)par1:(int)par2;
    name(Name,myPoint)Gives me:-(void)Name:myPoint;No problem. Simple.
    For (1) will:#define name(par1,par2) NSString par1 = @"par2";
    name(myName,myPoint)give meNSString myName = @"myPoint";
    or
    NSString Name = @"par2";
    From my understanding I think that will do what I want and give me @"myPoint".
    For (2) What I want is:#define name(par1,par2) -(void)makeSome'par1:(int)par2;
    name(Name,myPoint)and get
    -(void)makeSomeName:(int)myPoint;
    I haven't been defining macros in C for a long long time, and I know this is possible, just not what syntax to use to make it work. I used the quote character to show concatenation, which some other macro processors I have used use. Someone with experience here, point me to a reference on C preprocessor macros formatting would be good.
    A correct example on how to define the 2nd macro would also help
    There's really not much in my K&R C Programming language, circa 1978 2nd printing...

    There's a section on the preprocessor in the book Beginning Mac OS X Programming by Wrox, but it's all based around C, not Objective-C like the code in your examples, so I don't know if that would be helpful to you or not.
    I'm not a very experienced programmer, so I was hesitant to even reply, and I'll warn you now that I don't think this post will be of any help to you, but since you haven't gotten any other replies yet, I figured I'd try. Hopefully someone else around here will come along and actually help you.
    Anyways, let's say you had two functions defined in your program -- their declarations are:
    void PrintAddresses( );
    void PrintPhoneNumbers( );
    you could ideally use a macro as a way of calling the desired function. In C, the basic syntax for writing a macro like the one you wrote often uses the ternary operator. I don't know enough about Objective-C to know how that would fit in, but in C it would be simple enough:
    #define Macro(param1, param2) (condition ? PrintAddresses : PrintPhoneNumbers)
    the condition could be anything (param1 > param2 for example). Then, later, if you need to choose a method name based on the criteria passed to the macro, you would pass the appropriate arguments to the macro to get the ternary operator to return the desired value. The function call would be something like this:
    Macro(arg1, arg2)( );
    The compiler never sees the preprocessor directives. The preprocessor simply runs over your code before the compiler gets to it, replacing any macros with the values specified for them. So, if the arguments passed to the macro resulted in the condition in the ternary operator in the #define directive to be true, then the words "Macro(arg1, arg2)" would be replaced with "PrintAddresses" and your function call would now look like "PrintAddresses( );" and thus the function PrintAddresses( ) would be called. If the arguments passed to the macro resulted in the condition being false, then the words "Macro(arg1, arg2)" would be replaced with "PrintPhoneNumbers" and your function call would now look like "PrintPhoneNumbers( );" and thus the function PrintPhoneNumbers( ) would be called.
    Note that if you take out the word "Print" from the macro values and try to define the macro like this:
    #define Macro(param1, param2) (condition ? Addresses : PhoneNumbers)
    and call the function like this:
    PrintMacro(arg1,arg2)();
    it will not work like this (or at least I could not get it to work like this) -- I don't know why.
    Anyways, you probably already knew everything I just wrote, in which case maybe it can help someone else down the line searching through this thread. Or maybe I should just stick to asking questions on this forum. Anyways, hope the post wasn't a complete waste of time. Best of luck in solving your problem.
    Message was edited by: Tron55555

  • Identify TV shows as "first" run or "Re"Runs

    How do I identify TV shows as a first run or a rerun?  Just switched from Direct TV to Verizon Fios TV.  Direct TV identified the first time a TV show ran under "info" - apparently Verizon Fios does not.  Any suggestions?
    Thank you.
    JHJ

    Just another viewer who wishes the Guide would be more accurrate.  A lot of the time, they don't have any information, just a general
    program description, e.g. Leno, Dateline, etc.
    My very favorite was before a presidential debate between Obama and McCain.  For days, the Guide info was "Final presidential debate
    between Bush and Kerry".   I thought maybe they were going to re-run the '04 debate! 
    This just exemplified how awful the Guide is, and how nobody bothers to even read it (wherever it comes from), because I cannot believe
    anyone could be that badly uninformed. 

Maybe you are looking for

  • HDMI/TV/wifi/macbook

    When I connect my macbook to my TV, sometimes I lose my wifi connection. As soon as I disconnect it, the wifi comes back....can anyone help me fix this problem?

  • How do I get the original .ipa?

    I think I did something stupid, as I am known to do from time to time. I removed an .ipa file from my iTunes Media folder awhile ago, thinking it would delete the app. I guess I forgot and didn't pay attention and have been my merry way. Today I'm bo

  • Staging Tables in AP

    Hi I am a newbie to Peoplesoft and am trying to understand all the staging tables that are used in AP. Could somebody explain me the difference between VCHR_HDR_STG and VCHR_HDR_EC tables and when they will be used. The environment i am using is Fina

  • Looking for Q&A session from July 16th press conference on antenna issue.

    Does anyone know where I can find the rest of video, the Q&A session, from the July 16th press conference on the iPhone 4's antenna issue? The post on apple.com cuts it off. Kind of irritating because I'm experiencing the same issue, and I'd like to

  • Can we change the Home screen Background for iPhone 5C

    Can we change the Home screen Background for iPhone 5C