কম্পিউটার

C++ এ GCC কম্পাইলারের অন্তর্নির্মিত ফাংশন


GCC কম্পাইলারে কিছু বিল্টইন ফাংশন আছে। এই ফাংশনগুলো নিচের মত।

ফাংশন _builtin_popcount(x)

এই বিল্টইন ফাংশনটি একটি পূর্ণসংখ্যা টাইপ ডেটাতে 1s সংখ্যা গণনা করতে ব্যবহৃত হয়। আসুন _builtin_popcount() ফাংশনের একটি উদাহরণ দেখি।

উদাহরণ

#include<iostream>
using namespace std;
int main() {
   int n = 13; //The binary is 1101
   cout << "Count of 1s in binary of "<< n <<" is " << __builtin_popcount(n);
   return 0;
}

আউটপুট

Count of 1s in binary of 13 is 3

ফাংশন _builtin_parity(x)

এই বিল্টইন ফাংশনটি একটি সংখ্যার সমতা পরীক্ষা করতে ব্যবহৃত হয়। সংখ্যার বিজোড় সমতা থাকলে, এটি সত্য হবে, অন্যথায় এটি মিথ্যা হবে। আসুন _builtin_parity() ফাংশনের একটি উদাহরণ দেখি।

উদাহরণ

#include<iostream>
using namespace std;
int main() {
   int n = 13; //The binary is 1101
   cout << "Parity of "<< n <<" is " << __builtin_parity(n);
   return 0;
}

আউটপুট

Parity of 13 is 1

ফাংশন _builtin_clz(x)

এই বিল্টইন ফাংশনটি একটি পূর্ণসংখ্যার অগ্রবর্তী শূন্য গণনা করতে ব্যবহৃত হয়। CLz মানে Count Leading Zeros. আসুন _builtin_clz() ফাংশনের একটি উদাহরণ দেখি।

উদাহরণ

#include<iostream>
using namespace std;
int main() {
   int n = 13; //The binary is 1101
   //0000 0000 0000 0000 0000 0000 0000 1101 (32bit integer )
   cout << "Leading zero count of "<< n <<" is " << __builtin_clz(n);
   return 0;
}

আউটপুট

Leading zero count of 13 is 28

ফাংশন _builtin_ctz(x)

এই বিল্টইন ফাংশনটি একটি পূর্ণসংখ্যার পিছনের শূন্য গণনা করতে ব্যবহৃত হয়। ctz এর অর্থ হল Count Trailing Zeros. আসুন _builtin_ctz() ফাংশনের একটি উদাহরণ দেখি।

উদাহরণ

#include<iostream>
using namespace std;
int main() {
   int n = 12; //The binary is 1100
   //0000 0000 0000 0000 0000 0000 0000 1100 (32bit integer )
   cout << "Trailing zero count of "<< n <<" is " << __builtin_ctz(n);
   return 0;
}

আউটপুট

Trailing zero count of 12 is 2

  1. C++ এ ইনলাইন ফাংশন

  2. C++ এ log() ফাংশন

  3. C++ এ swap() ফাংশন

  4. কিভাবে লিনাক্সে C++ কম্পাইলার ইনস্টল করবেন?