extension etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
extension etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

26 Kasım 2019 Salı

gcc extension __builtin_clz

Örnek
Şöyle yaparız.
#include <iostream>

int main(){
    int i = 0;
    std::cout << __builtin_clz(0) << std::endl;
}

14 Kasım 2018 Çarşamba

gcc extension - __attribute__ packed

Giriş
Açıklaması şöyle.
The packed attribute specifies that a variable or structure field should have the smallest possible alignment—one byte for a variable
Not : Bu kodlar portable değil. gcc aynı zamanda Microsoft kodlarını da okuyabiliyor. Portable kod için #pragma pack() şeklinde kullanırız.

Örnek - C++

Şöyle yaparız
struct __attribute__((__packed__)) BitsField 
{
  // Logic values
  uint8_t vesselPresenceSw: 1;
  uint8_t drawerPresenceSw: 1;
  uint8_t pumpState: 1;
  uint8_t waterValveState: 1;
  uint8_t steamValveState: 1;
  uint8_t motorDriverState: 1;
    // Unused
  uint8_t unused_0: 1;
  uint8_t unused_1: 1;
};
Örnek - C
Şöyle yaparız.
struct packet {
  uint16_t mfg;
  uint8_t type;
  uint16_t devid;
} __attribute__((packed));
Örnek - 1 Byte
Açıklaması şöyle
To pack a class is to place its members directly after each other in memory
Şöyle yaparız.
struct Sensor1Telemetry {
  int16_t temperature;
  uint32_t timestamp;
  uint16_t voltageMv;
    // etc...
} __attribute__((__packed__));



2 Nisan 2018 Pazartesi

gcc extension - __attribute__ destructor

Giriş
 __attribute__ ((constructor)) ile main metodundan önce kod çalıştırmak

 __attribute__ ((destructor)) ile main metodundan sonra kod çalıştırmak mümkün.

Örnek
Şöyle yaparız.
#include<stdio.h>

/* Apply the constructor attribute to myStartupFun() so that it
    is executed before main() */
void myStartupFun (void) __attribute__ ((constructor));


/* Apply the destructor attribute to myCleanupFun() so that it
   is executed after main() */
void myCleanupFun (void) __attribute__ ((destructor));


/* implementation of myStartupFun */
void myStartupFun (void)
{
    printf ("startup code before main()\n");
}

/* implementation of myCleanupFun */
void myCleanupFun (void)
{
    printf ("cleanup code after main()\n");
}

int main (void)
{
    printf ("hello\n");
    return 0;
}
Örnek
Şöyle yaparız.
int main(void)
{
  ...;
}

__attribute__ ((destructor)) void after_main(void)
{
  ...
}

2 Ağustos 2017 Çarşamba

gcc extension - __attribute__

default
Derlerken şöyle yaparsak, Bu durumda visibility default olmayan semboller .so kütüphanesindeki export symbol table'a dahil edilmez.
-fvisibility=hidden
destructor
__attribute__ destructor yazısına taşıdım.
hidden
Eğer bir sınıfı .so kütüphanesindeki export symbol table'a dahil etmek istemezsek, kodda Şöyle yaparız.
class __attribute__ ((visibility ("hidden"))) Foo{
  ...
};
packed
__attribute__ packed yazısına taşıdım.