aliasing

gcc C/C++ assume no pointer aliasing

筅森魡賤 提交于 2019-11-30 13:04:40
Having recently read that the main reason why fortran is faster than c/c++ in numerical computations is because there is no pointer aliasing. Apparently, using restrict or __restrict__ keywords allows on a case by case basis to indicate the absence of pointer aliasing for a given memory element. The icc compiler apparently has an option -fno-alias which allows one to globally assume that no aliasing is present. On gcc there is -fno-strict-aliasing , which applies only to a subset of all the aliasing situations. Is there an option present in gcc, or are there some cases where no aliasing is

What is the difference between square brackets and single quotes for aliasing in SQL Server?

六月ゝ 毕业季﹏ 提交于 2019-11-29 01:50:13
问题 I have seen some people alias column names using single quotes eg: select orderID 'Order No' from orders and others use square brackets eg: select orderID [Order No] from orders I tend to use square brackets. Is there any preference/difference? 回答1: To answer the question "is there any preference/difference": Yes, there are as many preferences as there are opinions, but be careful whose preferences you adopt. As a best practice, it is advisable to write portable SQL if it doesn't require any

How to cast sockaddr_storage and avoid breaking strict-aliasing rules

柔情痞子 提交于 2019-11-28 16:53:03
I'm using Beej's Guide to Networking and came across an aliasing issue. He proposes a function to return either the IPv4 or IPv6 address of a particular struct: 1 void *get_in_addr( struct sockaddr *sa ) 2 { 3 if (sa->sa_family == AF_INET) 4 return &(((struct sockaddr_in*)sa)->sin_addr); 5 else 6 return &(((struct sockaddr_in6*)sa)->sin6_addr); 7 } This causes GCC to spit out a strict-aliasing error for sa on line 3. As I understand it, it is because I call this function like so: struct sockaddr_storage their_addr; ... inet_ntop(their_addr.ss_family, get_in_addr((struct sockaddr *)&their_addr)

How to cast sockaddr_storage and avoid breaking strict-aliasing rules

不打扰是莪最后的温柔 提交于 2019-11-27 10:01:58
问题 I'm using Beej's Guide to Networking and came across an aliasing issue. He proposes a function to return either the IPv4 or IPv6 address of a particular struct: 1 void *get_in_addr( struct sockaddr *sa ) 2 { 3 if (sa->sa_family == AF_INET) 4 return &(((struct sockaddr_in*)sa)->sin_addr); 5 else 6 return &(((struct sockaddr_in6*)sa)->sin6_addr); 7 } This causes GCC to spit out a strict-aliasing error for sa on line 3. As I understand it, it is because I call this function like so: struct

Nested structs and strict aliasing in c

烈酒焚心 提交于 2019-11-27 00:57:06
问题 Please consider the following code: typedef struct { int type; } object_t; typedef struct { object_t object; int age; } person_t; int age(object_t *object) { if (object->type == PERSON) { return ((person_t *)object)->age; } else { return 0; } } Is this legal code or is it violating the C99 strict aliasing rule? Please explain why it is legal/illegal. 回答1: Strict aliasing rule is about two pointers of different types referencing the same location in memory (ISO/IEC9899/TC2). Although your