c99

C, Open MPI: segmentation fault from call to MPI_Finalize(). Segfault does not always happen, especially with low numbers of processes

一世执手 提交于 2019-12-10 20:09:53
问题 I am writing a simple code to learn how to define an MPI_Datatype and use it in conjunction with MPI_Gatherv. I wanted to make sure I could combine variable length, dynamically allocated arrays of structured data on a process, which seems to be working fine, up until my call to MPI_Finalize(). I have confirmed that this is where the problem starts to manifest itself by using print statements and the Eclipse PTP debugger (backend is gdb-mi). My main question is, how can I get rid of the

Can output routines that print to a FILE* be used to build a string in C?

非 Y 不嫁゛ 提交于 2019-12-10 19:23:04
问题 I have a bad feeling that the answer to this question is "no", but I wanted to throw this out there in case anyone has any clever ideas. I have a set of output routines that take a complex data structure and print it in a textual format. They have prototypes like: void print_mystruct(struct mystruct *s, FILE *stream) I wrote it this way so that I can get efficient, buffered output to the terminal, to a file, to the network, etc. Unfortunately, there's no way that I know of, using standard C99

What is the definition of Incomplete Type and Object Type in C?

烈酒焚心 提交于 2019-12-10 17:28:49
问题 What is the definition of Incomplete Type and Object Type in C? Also, could you provide some examples of each? ANSI C99 mentions both type categories in various places, though I've found it difficult to understand what each of them means exactly (there is no paragraph/sentence explicitly defining what they are). 回答1: Let's go to the online C standard (draft n1256): 6.2.5 Types 1 The meaning of a value stored in an object or returned by a function is determined by the type of the expression

Using __thread in c99

前提是你 提交于 2019-12-10 17:18:26
问题 I would like to define a few variables as thread-specific using the __thread storage class. But three questions make me hesitate: Is it really standard in c99? Or more to the point, how good is the compiler support? Will the variables be initialised in every thread? Do non-multi threaded programs treat them as plain-old-globals? 回答1: To answer your specific questions: No, it is not part of C99. You will not find it mentioned anywhere in the n1256.pdf (C99+TC1/2/3) or the original C99 standard

DT_DIR undefined

十年热恋 提交于 2019-12-10 17:09:24
问题 I want to check if file returned by readdir is directory. I tried do it using DT_DIR constant (as man readdir says) but it's undefined. What file should I include to get it? Now I use #include <sys/types.h> #include <dirent.h> #include <stdlib.h> #include <errno.h> gcc version is 4.6.1 Compilation string: gcc a.c --std=c99 -Wall 回答1: You need to have the _BSD_SOURCE feature test macro defined to get those defines, they are not standard, and GCC does not define that macro when compiling for

Is there a recommended integer type to store function pointers in standard C

a 夏天 提交于 2019-12-10 16:57:42
问题 The C99 standard has uintptr_t , a recommended integer type to convert data pointers (pointers to objects) to, but I did not find an equivalent integer type to store function pointers. Did I overlook it? A specific compiler could define such a type even though it is not in the standard, but a compiler is more likely to state that a function pointer can be stored in (say) a uint64_t than to define a new type. Another difference is that it can make sense to do integer arithmetic on a data

Is there any way for a compound literal to have variable length in c99?

霸气de小男生 提交于 2019-12-10 16:24:20
问题 I know that arrays with lengths determined at runtime are possible by declaring the array normally: char buf[len]; and I know that I can declare an array as a compound litral and assign it to a pointer midway: char *buf; .... buf = (char[5]) {0}; However, combining the two doesn't work (is not allowed by the standard). My question is: Is there any way to achieve the effect of of the following code? (note len ) char *buf; .... buf = (char[len]) {0}; Thank you. 回答1: The language explicitly

Is using any indeterminate value undefined or just those stored in objects with automatic storage?

杀马特。学长 韩版系。学妹 提交于 2019-12-10 15:47:21
问题 According to C99 J.2, the behavior is undefined when: The value of an object with automatic storage duration is used while it is indeterminate What about all the other cases where an object has an indeterminate value? Do we also always invoke UB if we use them? Or do we invoke UB only when they contain a trap representation? Examples include: the value of an object allocated using malloc (7.20.3.3p2) [storing in non-automatic storage] a FILE* after calling fclose on it (7.19.3p4) [storing in

using restrict qualifier with C99 variable length arrays (VLAs)

混江龙づ霸主 提交于 2019-12-10 15:15:08
问题 I am exploring how different implementations of simple loops in C99 auto-vectorize based upon the function signature. Here is my code: /* #define PRAGMA_SIMD _Pragma("simd") */ #define PRAGMA_SIMD #ifdef __INTEL_COMPILER #define ASSUME_ALIGNED(a) __assume_aligned(a,64) #else #define ASSUME_ALIGNED(a) #endif #ifndef ARRAY_RESTRICT #define ARRAY_RESTRICT #endif void foo1(double * restrict a, const double * restrict b, const double * restrict c) { ASSUME_ALIGNED(a); ASSUME_ALIGNED(b); ASSUME

Are enums as bitfields implementation-defined types?

ⅰ亾dé卋堺 提交于 2019-12-10 15:12:42
问题 I'm trying to better understand the C99 standard but now I'm confused about using enums as bitfields in structs and if they are treated as int or as implementation-defined type. When looking up in the final draft for C99, I found 6.7.2.1 para. 4 A bit-field shall have a type that is a qualified or unqualified version of _Bool , signed int , unsigned int , or some other implementation-defined type. and 6.7.2.2 para. 4 Each enumerated type shall be compatible with char , a signed integer type,