concatenate prefix in the function name with macro?

c macro concatenate string and int
c define macro function
# and ## in c
c preprocessor concatenate two macros
c macro arguments
c macro string
c macro function
concat string in macro

I want to concatenate some macro in the beginning of function name:

#include <stdio.h>

#define PFX mypfx

int PFX##_call() {

int main(void)

The above code return error in compilation.

How to add prefix with macro in the function name?

Why don't you use a namespace instead:

namespace mypfx
    int call() {

int main(void)

Concatenation (The C Preprocessor), It is often useful to merge two tokens into one while expanding macros. This is The string constant can be created with stringizing, and the function name by  VBA Concatenate – Example #1. As we do not have any built-in functions in VBA, concatenation in VBA can be achieved by using ampersand (&) operator. We will take the same example which is already we took for the worksheet function. We have “I love” in cell D4 and “India” in cell E4. Now we will combine those two strings in VBA.

The ## operator only allows you to concatenate two strings inside another macro definition.

But this:

int PFX##_call()

is not a macro definition, therefor it will expand to this which is invalid C:

int mypfx##_call()

Example of valid usage:

#define FOO 1
#define BAR 2
#define FB FOO##BAR    // FB will expand to FOOBAR
                       // independently of the macros FOO and BAR

#define BF FOO BAR     // BF will expand to 1 2

Carpenter's Complete Guide to the SAS Macro Language, Third Edition, Each macro variable name starts with the prefix 'NAME', and the CATT function is used to concatenate the number of each successive name (CNT) onto the  Concatenation means joining two values or two strings together, similar to excel we use & or also known as ampersand operator to concatenate, two concatenate two strings we use & operator like String 1 & String 2, now there is an important thing to remember and that is while using the & operator we need to provide spaces or VBA will consider it as long.

I don't know why you would want to do this (maybe because you want to "emulate" namespaces), but assuming you're in C, you can achieve it with the following code.

#define concat2(X, Y) X ## Y
#define concat(X, Y) concat2(X, Y)
#define pfx(x) concat(pfx_, x)


int pfx(sum)(int x, int y) {
    return x + y;

int main() {
    printf("%d\n", pfx(sum)(5,4));

Note: if you want to use more macro processing power (i don't know if it's you case) you should visit P99

The Java Native Interface: Programmer's Guide and Specification, class Prompt [ // native method that prints a prompt and reads a line private and JNICALL macros (defined in the jni.h header file) ensure that this function is The name of the C function is formed by concatenating the “Java_” prefix, the  Even there is a separate function for concatenation in worksheet functions. But in VBA it is not that similar, in VBA there is no inbuilt function for concatenation of strings also neither can we use the worksheet functions for the same. The only method to concatenate strings in excel VBA is by using the & and + operator.

Enterprise Systems Integration: A Process-Oriented Approach, The return type for the function is specified between those two macros. obtained by concatenating the prefix Java_ with the class name and the method name. You don't want to use CATX(), you want to use TRANWRD(). In general there is not much use for the CAT function in macro code. If you want to add the prefix P to every value in a space delimited list then just prefix the first word and change the delimites to include the prefix for the following words.

Trends in Functional Programming: 14th International Symposium, , A place function is created by prepending the make-prefix to the identifier function name is formed by concatenating the define-named-remote-server identifier,  This is called token pasting or token concatenation. The ‘##’ preprocessing operator performs token pasting. When a macro is expanded, the two tokens on either side of each ‘##’ operator are combined into a single token, which then replaces the ‘##’ and the two original tokens in the macro expansion. Usually both will be identifiers, or one will be an identifier and the other a preprocessing number.

The C Preprocessor, For example, `#define' must be followed by a macro name and the intended A macro that accepts arguments is called a function-like macro because the syntax for The directory's name is made by concatenating prefix and dir , where prefix​  WPP - Concatenate trace macro parameter with trace format string, in the preprocessor you can orchestrate things so that the function name is the MSG, so it can

  • Why? Really, it just seems like an exercise in obfuscation.
  • what do you actually want to achieve? smells like xy problem
  • macros like this are a great way to have people never want to use or maintain your code
  • please choose one lanuguage, in c++ there are 1 maybe 2 use cases for macros (yours is not one of them), in c I dont know
  • What's the point? So you can write PFX_myfunc() instead of mypfx_myfunc()? I don't see the point.
  • This is only valid for C++.
  • @Jabberwocky Yet another reason to always prefer C++ over C! :)