Archive for the ‘Cpp’ Category

Setup and Use GCC on Windows in 5 Easy Steps

Do you want to be able to compile C, C++, Ada and Fortran programs on Windows without losing time wrestling with a bulk, resource-intensive IDE? You can! The solution is to port the ultra-popular, lightweight GCC (GNU Compiler Collection) often used in *nix systems to Windows via MinGW + Cygwin.

MinGW is the minimalist GNU implementation for Windows.

If you’re like me then by the time you’ve come to the realization that you want to use MinGW and GCC on Windows for coding purposes, you’ve probably already installed it as a dependency of other software you might run, such as Anaconda or along with your Cygwin install (if so, skip to Step 3).

1. Install Cygwin, which provides many Linux commands/libraries to Windows

2. Install MinGW

3. Make sure that MinGW was added to your PATH by typing PATH in a terminal

If not, you can add it through Window’s GUI interface (just type PATH or Environment in Start on Win 7 or 8 and it will come right up as a search result).

4. In a terminal (cmd or PowerShell) go to the directory containing the code you want to compile, i.e.

cd c:\Users\Hackr\coolcode

5. Type the compile command:

g++ hackr.c -o hackr.exe

where -o is indicating your output file.

This also works with compiling multiple files:

g++ hackr.c econometrics.c hadoop.c overflow.c -o hackeconometrics.exe
That’s it!

This should take at least an hour or 2 less time than installing Microsoft’s Visual Studio (though the latter has it’s virtues) or a similar bulky IDE and will give you fewer headaches by avoiding complicating your life with a million unnecessary options and confusing attempts to “help” you build a simple project.

BabyGnu

Software Sec: C / C++ Buffer overflows and Robert Morris

Buffer Overflow = any access of a bugger outside of its allotted bounds
  •      over-read or over-write
  •      could be during iteration (running off the end), or direct access (pointer arithmetic)
  •      this is a general definition; some people use more specific definitions of differing types of buffer overflows

A buffer overflow is a bug that affects low-level code, typically C and C++ with significant sec implications

Normally causes a crash, but can be used to:
  • dump/steal information
  • corrupt information
  • run code (payload)
They also share common features with other bugs.
C and C++ are the most popular languages (behind Java) and therefore buffer overflows are a major vuln. C/C++ are heavily used in:
  •      OS Kernels
  •      embedded systems
  •      HPC servers
 First buffer overflow occurred in 1988 by a student named Robert Morris, as part of a self-propagating computer worm that was an attack against fingerd and VAXes (Morris was caught and punished but is now a MIT professor); this worm affected 10% of the Internet
In 2001, CodeRed exploited a buffer overflow in the MS-IIS server, which infected >300,000 machines in 14 hours
In 2003 SQL Slammer worm infected 75,000 machines in 10 minutes by exploiting a buffer overflow in MS-SQL Server
In 2014 a latent buffer overflow bug was found in X11 that had been present over 23 years.

 

 

C: C v. C++, Object Orientation

C++ graphs object oriented programming* tools to the C language

In the 1990s many companies began using C++ for large programming projects
C++ is a superset of C, any C program is (or almost is) a valid C++ program

*object-oriented programming philosophy attempts to mold the language to fit a problem instead of mold a problem to fit a language

C: When to use C v. C++

You pick C when

  • you need portable assembler (which is what C is, really) for whatever reason,
  • your platform doesn’t provide C++ (a C compiler is much easier to implement),
  • you need to interact with other languages that can only interact with C (usually the lowest common denominator on any platform) and your code consists of little more than the interface, not making it worth to lay a C interface over C++ code,
  • you hack in an Open Source project (many of which, for various reasons, stick to C),
  • you don’t know C++.

In all other cases you should pick C++.

 

Source:

https://programmers.stackexchange.com/questions/113295/when-to-use-c-over-c-and-c-over-c?newreg=6fa78b0778654732957cf2d72648ea00