Questions tagged [ansi-c]

ANSI C is an informal term sometimes used when referring to the C programming language standard published by the American National Standards Institute (ANSI) in 1989 .

"ANSI C" is an informal term used to refer to the 1989 version of the C language. The formal name for this version of the language is ISO/IEC 9899:1990. Informally it is also known as "C89" or "C90".

This is because the American National Standards Institute (ANSI) first published this standard in the year 1989, as a national standard for the USA. It became international ISO standard in the year 1990. So ANSI C, C89 and C90 all refer to the same technical standard.

It is a common misunderstanding that "ANSI C" means standard compliant C. The ANSI standard institute haven't had anything to do with C since 1989. The language is maintained by ISO SC22/WG14. Yet the term "ANSI C" is sometimes used to mean standard compliant, particularly in old books and by old compilers.

Because of this ambivalent meaning, please avoid using this tag. For questions regarding the C89/C90 version of the C language, please use . For questions regarding standard-compliant C, simply use the tag.

Further information about the different C standard versions.

618 questions
2
votes
1 answer

Zigzag array in ANSI C

I'm just a beginner and I'm trying to figure out how to create two-dimensional array, filled with numbers diagonally like in JPEG zigzag ordering: https://en.wikipedia.org/wiki/File:JPEG_ZigZag.svg I figured out how to get the upper-left…
Piotr
  • 47
  • 6
2
votes
3 answers

What uses up more space in FLASH? static variable or global variable

As the title says, what uses up more space in FLASH (in an STM32 µC for example)? Declaring a global variable or declaring a static variable inside a function? Or do they take equal space? Both variables are available throughout the whole runtime of…
BertVano
  • 219
  • 3
  • 11
2
votes
1 answer

Adding a node to server's address space in OPC UA ANSI C stack

I have a problem with OPC UA ANSI C stack, a very simple project for a subject: simply add a node to the server's address space, so that a client can then read it. I know there is the open source ANSI C stack (open62541), but I need to use the…
2
votes
2 answers

How to multiply floating point in ANSI C?

The following code: float numberForFactorial; float floatingPart = 1.400000; int integralPart = 1; numberForFactorial = ((floatingPart) - (float)integralPart) * 10; printf("%d", (int)numberForFactorial); Returns 3 instead of…
Nikitas
  • 1,013
  • 13
  • 27
2
votes
1 answer

Remove text from string after a certain character in C

I am reading lines from a file, the lines look like this: 89f81a03eb30a03c8708dde38cf:000391716 The thing is: I want to remove everything after the : (including the :). I tried everything I could find online but they seem to use const char and the…
2
votes
1 answer

Multiple definitions and First defined error

I have written a small C program which is assembled of several files. When I compile, I get an error for "multiple definitions". My main.c: #include #include #include #include "general_structs.h" #define FOREVER…
JinKazama
  • 81
  • 3
  • 15
2
votes
1 answer

Meta language to code generate packed structs for ANSI-C and C# Structs

I'm trying to find a "meta language" that can be used to define a structure and get/set code for members. The catch is that the structure already exists in code, and this "meta language" would serve as bit-for-bit replacement of the original…
DGtlRift
  • 53
  • 1
  • 5
2
votes
1 answer

Cast multidimensional array to multidimensional array of another type

I have const uint8_t longByteTable[16][256][16] = { { { 0x00, ... } } }; declared as a three-dimensional 16x256x16 array of hardcoded octet values. For optimisation purposes and various other reasons I need this array to be interpreted as a…
aprelev
  • 390
  • 2
  • 11
2
votes
1 answer

Segmentation fault in accept system call

I have the following code serving as main loop for a server that accepts incoming socket connections. At the moment the macro OperationMode is defined as 1 so it will execute the pthread logic. for (hit = 1 ;; hit++) { printf("Got…
rafaelcpalmeida
  • 874
  • 1
  • 9
  • 28
2
votes
6 answers

Is there any way of finding out what type of struct a pointer points to?

My program contains several structs which only have one parameter in common. Ex: struct first { var a; var b; var common_var; var c; }; struct second { var d; var common_var; var e; var f; }; The "common_var" is the…
pose
  • 21
  • 3
2
votes
1 answer

Why would someone add zero to __STDC_VERSION__?

Looking through stdarg.h, I spotted the following: #if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L #define va_copy(d,s) __builtin_va_copy(d,s) #endif Is there a purpose to adding 0 in the expression?
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
2
votes
2 answers

Error when parsing line of CSV text

I fail parsing a CSV file in C. I need to file a struct with data from that file. This is the relevant part of my structure: typedef struct Info { /* Some strings, integers, etc. */ char correct; /* This is the value I can't set */ short…
LuMa
  • 1,673
  • 3
  • 19
  • 41
2
votes
3 answers

Sorting a 2D array with qsort

I'm trying to sort 2d array. First i sort it by column, then by rows. Column by column is working but row by row not. What's wrong in this code? int scmpr (const void *a, const void *b){ return strcmp((const char*)a, (const char*)b); } int…
Krasnal
  • 85
  • 2
  • 9
2
votes
2 answers

Pass variable number of arguments received to another function

Before you say it's duplicated, I already read this: How to pass variable number of arguments from one function to another? I have a function like this: void tlog_function(t_log* logger, const char* message_template, ...) { …
Pablo Matias Gomez
  • 6,614
  • 7
  • 38
  • 72
2
votes
1 answer

Translational Limits on Enum Constants

I have a very specific question about the translation limits of C (as defined in the ANSI/ISO 9899:X standards family) regarding enumeration constants. I have some thousand individually indentifyable data sources, I'd like to enumerate. Also I want…
Mark A.
  • 579
  • 4
  • 13