Programming c on windows

This is a discussion on Programming c on windows within the C Programming forums, part of the General Programming Boards category; Hi, I've just completed a short course on c programming, where we used linux as a platform - editing with ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    110

    Programming c on windows

    Hi, I've just completed a short course on c programming, where we used linux as a platform - editing with gedit, and compiling with gcc from the command line. I wan't to start making some programs on windows as a part of some electronics projects and don't know where to start. I assume you can do it for free without having to download any IDE's? For instance how do I start editing and compiling?

    Also is there any difference between programming on XP and vista?

    Thanks
    PHI is one 'H' of alot more interesting than PI!

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Starting from the back: XP and Vista are the same for 99.9% of the code most people write. If you work with Graphics device drivers, then the difference is as between an electric car and a diesel car - not much in common at all except they ultimately do (roughly) the same thing. So in details, there are some huge differences, but in general, a program written for one should work on the other - particularly moving XP -> Vista.

    As to compiling: Windows is not distributed with a compiler - MS wants you to pay them for the pleasure. You can get free compilers, with or without IDE.
    gcc-mingw is almost identical to the gcc [and related tools] that you use in Linux.
    Microsoft have a free [as in beer] version of Visual Studio (IDE + Compiler), called Express Edition.
    There is code::blocks that is a free (in both meanings of the term) IDE and can be downloaded with an included gcc-mingw installation, so it's one single packet to download if you go for that too.
    (X)emacs is available as an editor for both - and there are other editors that also work on both, but I haven't bothered looking for a list of which ones.

    The advantage with working on a gcc-related version is that the error messages you get are (almost always) identical to the same mistake on Linux - which means that at least some of those "confusing" error messages that you get when the compiler didn't understand at all what you meant (missing semicolon is a typical one which often leads to cryptic error messages).

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Hi matsp, thanks for the info. Mingw looks ok I'll probably get started with that. for one program I need to use the include files dos.h and conio.h for interfacing with the parallel port. I assume this is ok to do? (dos.h obviously won't work with linux for example, but I'm assuming this is purely a restriction of linux not being ms-dos based, and has nothing to do with the GCC compiler as well)
    PHI is one 'H' of alot more interesting than PI!

  4. #4
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    If you don't care about making "windows programs", try cygwin.

    Quzah.
    Hope is the first step on the road to disappointment.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    In Windows, the parallel port is "off limits" - it belongs to the parallel port driver, and anything else "messing" with that port will not work right (or make the ppdriver not work). But to access ANY port in Windows, you need driver code.

    It is not a case of existance or the ability to include files, but rather that Windows [and Linux] prevents user-mode code from accessing hardware devices in general.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Hi matsp, then what is the conio.h library all about? I thought this included functions for parallel port I/O. I have seen a couple of examples of c code where conio.h has been included to communicate with the prallel port, including a porject for stepper motor control in an electronics magazine.

    I thought it was linux that had had security issues with this?
    PHI is one 'H' of alot more interesting than PI!

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    conio.h traditionally contains things like getch() and gotoxy(). dos.h would contain things that are directly DOS (and closely related, it probably holds "outport()" or whatever the function to output something to a port is.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #8
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Yeh but doesn't this allow you to access the parallel port registers?

    Also I have some code here for checking the BIOS data area to obtain the memory locations of the different ports connected to your PC:

    Code:
    #include <stdio.h>
    #include <dos.h>
     
    void main(void)
    {
      unsigned int far *ptraddr;  /* Pointer to location of Port Addresses */
      unsigned int address;        /* Address of Port */
      int a;
    
      ptraddr=(unsigned int far *)0x00000408;
    
      for (a = 0; a < 3; a++)
      {
        address = *ptraddr;
        if (address == 0){
          printf("No port found for LPT%d \n",a+1);
        }else{
          printf("Address assigned to LPT%d is %Xh\n",a+1,address);
          *ptraddr++;
        }
       }
    }
    I understand there's a pointer to the base location of the LPT1 address in the BIOS data area, then it scans them one by one to find the adresses of LPT1, LPT2, and LPT3. I don't understand the variable type "unsigned int far" though, and the syntax used in this line:

    ptraddr=(unsigned int far *)0x00000408;

    I've only used pointers to point at another variable I've declared, and not to point to a specific memory location.

    Also can I sucessfully use this code on Vista with MinGW?

    Thanks
    PHI is one 'H' of alot more interesting than PI!

  9. #9
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    It is a lesser-known fact that you can get Microsoft's compiler for free (with MFC, to boot) simply by downloading the WDK.

    EDIT: Obviously, using the WDK to compile commercial application products for release goes against the license agreement (same goes for Studio Express)
    Last edited by brewbuck; 04-16-2009 at 11:23 AM.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  10. #10
    'Allo, 'Allo, Allo
    Join Date
    Apr 2008
    Posts
    611
    Quote Originally Posted by brewbuck View Post
    EDIT: Obviously, using the WDK to compile commercial application products for release goes against the license agreement (same goes for Studio Express)
    That's incorrect
    Quote Originally Posted by http://www.microsoft.com/express/support/faq/
    Can I use Express Editions for commercial use?

    Yes, there are no licensing restrictions for applications built using Visual Studio Express Editions.
    The WDK license (largely this though it's structured slightly differently) doesn't forbid it either.

  11. #11
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,246
    Quote Originally Posted by adeyblue View Post
    The WDK license (largely this though it's structured slightly differently) doesn't forbid it either.
    IANAL, but this language seems to support my statement:

    solely for the purpose of designing, developing and testing drivers

    I.e., not applications.

    As far as Studio Express, I guess my memory is failing.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  12. #12
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Hi thanks for all the replies. I'm just wondering can I program things in dos using MinGW and cygwin?

    I don't want to be able to make full blown applications with GUI's on windows.

    Also, I've installed MinGW and MSYS but I don't know where to start.
    PHI is one 'H' of alot more interesting than PI!

  13. #13
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Some nice IDE's to use in Windows are:
    - Dev-C++: Bloodshed Software - Dev-C++
    - Pelles C: smorgasbordet - Pelles C

    Pelles C is easy for Win32 API (GUI too) development.

    Edit: oh I see, you DON'T want to develop GUI in windows . Yes you can develop programs without GUI (in the command prompt).
    Last edited by Ideswa; 04-17-2009 at 12:58 PM. Reason: Correction
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  14. #14
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Thanks

    How do I start writing and compiling programs then? For instance in linux I would use gedit to write a program, and compile it from a terminal.
    PHI is one 'H' of alot more interesting than PI!

  15. #15
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    Well, Dev-C++ is an easy starter. It's an IDE (Integrated Development Environment). This means you have editor, compiler, debugger etc all in one program. Similar is Netbeans 6.5 for C, which can be used on linux too.

    Dev-C++ automatically installs MinGW and when you have written a program you can easily compile and run it from within Dev-C++.
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Windows 98/2000 programming in Windows XP
    By Bill83 in forum Windows Programming
    Replies: 3
    Last Post: 07-22-2005, 02:16 PM
  2. Dialog Box Problems
    By Morgul in forum Windows Programming
    Replies: 21
    Last Post: 05-31-2005, 05:48 PM
  3. dual boot Win XP, win 2000
    By Micko in forum Tech Board
    Replies: 6
    Last Post: 05-30-2005, 02:55 PM
  4. SDL and Windows
    By nickname_changed in forum Windows Programming
    Replies: 14
    Last Post: 10-24-2003, 12:19 AM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 05:31 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21