Search notes:

Predefined preprocessor macros __FUNCTION__, __FILE__, __LINE__

Note, __FUNCTION__ is not really a macro: the preprocessor has now concept of functions and thus doesn't not know in which function it is.

print_function.h

#include <stdio.h>
#define PRINT_FUNCTION(TXT) printf("%-10s %-10s: %4d: %s\n", __FUNCTION__, __FILE__, __LINE__, TXT);
Github repository about-cpp, path: /preprocessor/macros/predefined/__FUNCTION__FILE__LINE__/print_function.h

funcs.c

#include "print_function.h"
#include "funcs.h"

void func_a(const char* txt) {
  PRINT_FUNCTION(txt);
}

void func_b(const char* txt) {
  char buf[100]; // beware the buffer overflows…
  sprintf(buf, "txt = %s", txt);
  PRINT_FUNCTION(buf);
}
Github repository about-cpp, path: /preprocessor/macros/predefined/__FUNCTION__FILE__LINE__/funcs.c

main.c

#include "print_function.h"
#include "funcs.h"

int main() {

  PRINT_FUNCTION("starting up");

  func_a("abc");
  func_b("def");

}
Github repository about-cpp, path: /preprocessor/macros/predefined/__FUNCTION__FILE__LINE__/main.c

funcs.h

void func_a(const char* txt);
void func_b(const char* txt);
Github repository about-cpp, path: /preprocessor/macros/predefined/__FUNCTION__FILE__LINE__/funcs.h

Makefile

all: print-functions

main.o: main.c print_function.h funcs.h
	gcc -c main.c

funcs.o: funcs.c print_function.h funcs.h
	gcc -c funcs.c

print-functions: funcs.o main.o
	gcc funcs.o main.o -o print-functions

Github repository about-cpp, path: /preprocessor/macros/predefined/__FUNCTION__FILE__LINE__/Makefile

See also

Preprocessor: macros
https://github.com/ReneNyffenegger/about-cpp/tree/master/preprocessor/macros/predefined/__FUNCTION__FILE__LINE__
__LINE__, __FILE__ and __DIR__ in PHP.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1740174363, '3.139.66.35', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/C-C-plus-plus/preprocessor/macros/predefined/__FUNCTION__FILE__LINE__(110): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78