Tag: c

Entries for tag "c", ordered from most recent. Entry count: 2.

Warning! Some information on this page is older than 5 years now. I keep it for reference, but it probably doesn't reflect my current knowledge and beliefs.

Pages: 1

# Hotkey for Macro Inserting Text

Aug 2011

I recently code in C - an ancient language with no support for namespaces. To code a bigger system and not create name conflicts, prefixes for all public identifiers must be used. But they not only make the code less readable, but also take lots of time to type. I thought that at least the second issue can be minimized by setting up some macro that would insert predefined text (like "rendering_"), whenever I press a hotkey button (like Pause/Break).

I couldn't find such feature in my Visual C++ 2010 Express, so I decided to look for some general tool for Windows that can trigger a script when a hotkey is pressed. I found AutoHotkey - a free application with its own scripting language that claims to be successor of AutoIt, which I used some time ago. After reading some documentation, I coded following script:

SetKeyDelay -1
send rendering_

SetKeyDelay -1

If you have AutoHotkey installed, just save this code to a file, give it "ahk" extension and double-click to run it. Program will create a system tray icon for this script indicating that it's running in the background. From now on you can just press Pause key to insert text "rendering_" to whatever input control you are focused, or Shift+Pause to insert "RENDERING_". It really speeds up coding in C :)

Comments | #windows #tools #c Share

# C primer for C++ programmers

Sep 2009

I've never learnt pure C programming language, only C++. It does not mean I never use global variables or fopen function, but I it makes no sense for me to code in pure C when there is a C++ compiler available. But today I've decided to skim the classic book "The C Programming Language" by Brian W. Kernighan and Dennis Ritchie. Here is what I've found out:

You can actually code in C using Visual C++. To do this, you need to: (+) Create empty project, (+) Add a file with .c extension, (+) Enter project options, (+) Nagivate to Configuration Properties / C/C++ / Advanced, (+) Set "Compile As" to "Compile as C Code (/TC)".

The C language is similar to C++ except it lacks features such as:

There are some differences between C++ and C though. For example, you don't have to state type of function parameter or return type if you want to it to default to int. Following lines are equivalent:

int MyFunc1(int a, int b) { }
MyFunc2(a, b) { }

Compiler is generally more liberal when it comes to type checking and function calling. You can call function with more arguments than expected and it only generates warning. You can declare function with empty parameter list like MyFunc() which means unknown parameter list! To explicitly state that a function takes 0 parameters you have to write MyFunc(void).

Local variables can be defined only before any other statements in a block. You also cannot define a variable inside for loop. Example:

void Func(void)
  int a = 1; // OK
  int b = 2; // Error!
    int c = 3; // OK

C requires different syntax for using structures. If you define a structure like this:

struct Struct1 { int x; };

You have to prefix the name of this type with "struct" keyword each time you use it, just like this:

struct Struct1 *myObj;

But luckily typedef construct works in C, so the common solution to this problem is to use it like this:

typedef struct { int x; } Struct1;
Struct1 *myObj;

Comments | #c++ #c #visual studio Share

Pages: 1

[Stat] [STAT NO AD] [Download] [Dropbox] [pub] [Mirror]
Copyright © 2004-2017