大宝剑
i think it's safe, maybe this is why some symbols has the tag:
https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/_kernel/
大宝剑
The following kernel-mode libraries provide support for drivers: Core Kernel Library Support Routines Executive Library Support Routines Run-Time Library (RTL) Routines
Anonymous
#ifdef __cplusplus extern "C++" { template <typename _CountofType, size_t _SizeOfArray> char (*__countof_helper(_UNALIGNED _CountofType (&_Array)[_SizeOfArray]))[_SizeOfArray]; #define __crt_countof(_Array) (sizeof(*__countof_helper(_Array)) + 0) } #else #define __crt_countof(_Array) (sizeof(_Array) / sizeof(_Array[0])) #endif
This can be used only in those cases where the array is in scope. The original question how to get the size of an array when it is passed to a function. This method won't work there because the array would have decayed to a pointer by then. The only way around this is if the array is passed by reference (the msdn code you shared uses this concept) or if you pass a separate size argument to the function or if you use a sentinel value to mark the end of the array or if you pass iterators to the beginning and the end of the array
Bhaskarjyoti
anyone has gate cse made easy course
imminent
what
...
???
imminent
😂
\Device\NUL
😂
fine i will clarify my previous word. native api should not be used for general use except for specific case. Please correct me i'm wrong :"
what is the output of int = 1; printf("%d %d %d",a,++a,a++);
int a = 1 *
Abhishek
Hi i am seeking help in webrtc. anyone knows?
Börke(МБорке)
Hi is there anyone who knows Vscode well?
Buffer
Can we initialise a char pointer like this: char* p = {'H','e','l','l','o','\0'};
Buffer
why?
\Device\NUL
No
I thought It's allowed
Danya🔥
why?
Because it doesn't make any sense
Buffer
but it compiles successfully in vs code by just giving warning
Danya🔥
It cannot compile in VS Code, because VS Code is not a compiler
Buffer
It cannot compile in VS Code, because VS Code is not a compiler
sorry i mean gcc compiler compiles it by just giving a warning
\Device\NUL
Please use pedantic with learning so you know what's allowed in standard and what is not.
\Device\NUL
sorry i mean gcc compiler compiles it by just giving a warning
It because the char treated as integer. You know ASCII value right
Ludovic 'Archivist'
what is the output of int = 1; printf("%d %d %d",a,++a,a++);
This is undefined in C, undefined in C++ versions lower than 17, and "1 1 3" for later versions (if you add the missing "a" to the int declaration)
\Device\NUL
https://stackoverflow.com/questions/2934904/order-of-evaluation-in-c-function-parameters Found it
Elfa Metesar
std::array is kinda better if you just need the size
\Device\NUL
std::array is kinda better if you just need the size
Vectors allocation are on heap while std::array is just wrapper to C array. https://devblogs.microsoft.com/oldnewthing/20230811-00/?p=108591
Elfa Metesar
that's what im saying
Elfa Metesar
std array is on the stack, no need for unnecessary heap allocation
Kenshin
How to find array size in a function in which array is passed as a parameter?
In C++, template <class T, std::size_t N> constexpr std::size_t size(const T (&array)[N]) noexcept { return N; } However, in production code, please visit this link and use the utility addressed, https://en.cppreference.com/w/cpp/iterator/size
21BCS1029_Jalani_Aniruddh
Well I quite didn't get that but thanks all of you for answering my question yourself
Kasra
Hi everyone, I'm a 17-year-old looking to start programming. I've heard that C++ is a good language to start with, but I'm wondering if it might be too challenging for a beginner. Can someone offer some advice?
klimi
Hi everyone, I'm a 17-year-old looking to start programming. I've heard that C++ is a good language to start with, but I'm wondering if it might be too challenging for a beginner. Can someone offer some advice?
I think that if you just want to learn language, c++ might be difficult; if you are just seeking to learn programming, c++ is okay choice to learn the basics (if you want to know some lower level stuff too).
Elfa Metesar
Well I quite didn't get that but thanks all of you for answering my question yourself
well just use std::array instead of regular arrays, and use array.size() function. it's easy
21BCS1029_Jalani_Aniruddh
Ok
Elfa Metesar
#include <array> int main() { std::array<int, 5> arr{1,23,3,5,2}; std::cout << arr.size() << std::endl; }
Anonymous
In C++, template <class T, std::size_t N> constexpr std::size_t size(const T (&array)[N]) noexcept { return N; } However, in production code, please visit this link and use the utility addressed, https://en.cppreference.com/w/cpp/iterator/size
This would work only if the array is in scope and since C++17 you can just use std::size(arr_name) to determine the array size as long as arr_name is actually an array and not a decayed pointer
Timur
Is it possible to create a content editor similar to what Corona Render has, using only Blueprint tools in Unreal Engine to ensure usability?
klimi
?
itsmanjeet
?
The above code block, I am not that good in modern c++. For me its like regex pattern code, understandable and make life easy (*love) but I am unable to make them work on my own, (*not hate) I just reuse them from google
Anonymous
constexpr is from std 17?
It is actually from C++11 but that function doesn't need constexpr or noexcept It would work even without that.
Anonymous
Correct me, That will not working on any raw array right ? int[], only std containers
It will work only on raw arrays that are in the scope in which the function is being called. It won't work on standard containers. You don't need such a function for standard containers. They all already provide a method called size
Ludovic 'Archivist'
itsmanjeet
It will work only on raw arrays that are in the scope in which the function is being called. It won't work on standard containers. You don't need such a function for standard containers. They all already provide a method called size
Uhh, ohk ye until compiler hold that info. I am just thinking it like some generic method to call size() like the top most example on the provided *Possible Implements*
itsmanjeet
Also I use sizeof(a.0)/sizeof a for raw array Any benefit like performance or something over it ?
Anonymous
Also I use sizeof(a.0)/sizeof a for raw array Any benefit like performance or something over it ?
You should just use std::size post C++17. No benefits between the choices as all of them are evaluated at compile time. The only problem with the function is that some inefficient compiler may cause template bloat where it creates versions of that function for each data type and data size. Most modern compilers won't.
Anonymous
Hello everyone , so I declared a Struct with a member of type <vector>. For example: .... #include <vector> #define s 5 struct Student{ std::vector <int> v(s); }; This code is not running, when I created vector with a size, but if I make this: .... #include <vector> #define s 5 struct Student{ std::vector <int> v; }; The code execute. But when I created with the <array> it's running: .... #include <array> #define s 5 struct Student{ std::array <int,s> v; }; and also with std array or "int v[s];" this code is executing. Why that the class vector is not function when I create with a size?
Anonymous
Hello everyone , so I declared a Struct with a member of type <vector>. For example: .... #include <vector> #define s 5 struct Student{ std::vector <int> v(s); }; This code is not running, when I created vector with a size, but if I make this: .... #include <vector> #define s 5 struct Student{ std::vector <int> v; }; The code execute. But when I created with the <array> it's running: .... #include <array> #define s 5 struct Student{ std::array <int,s> v; }; and also with std array or "int v[s];" this code is executing. Why that the class vector is not function when I create with a size?
Kenshin
This would work only if the array is in scope and since C++17 you can just use std::size(arr_name) to determine the array size as long as arr_name is actually an array and not a decayed pointer
You have simply reiterated what I stated in my response. Revisit it and see that I ended by pointing to a link on cppreference.com; it is the page for std::size. Similar note, my implementation was picked straight out of the std::size example implementation, cause that is the overload of std::size that takes a built-in array.
Kptaan
Why?
Elfa Metesar
offtopic, ad
Kptaan
By mistake
Elfa Metesar
oh alr, i assumed you were a spambot anyway
Kptaan
No problem
Dibro
Learning c++
klimi
1,2,2
or 3,3,1, or anything else
%Nikita
what is the output of int = 1; printf("%d %d %d",a,++a,a++);
Isn’t it ub? I thought compilers can choose order of computing arguments
\Device\NUL
Isn’t it ub? I thought compilers can choose order of computing arguments
Yes, standards didn't say about evaluation order. https://t.me/programminginc/506760
Ludovic 'Archivist'
This is Unspecified Behavior in C++.
From C++17 onwards, it is specified as being left to right
Anonymous
From C++17 onwards, it is specified as being left to right
https://en.cppreference.com/w/cpp/language/eval_order This is the point that applies to this particular question. 15) In a function call, value computations and side effects of the initialization of every parameter are indeterminately sequenced with respect to value computations and side effects of any other parameter.
Anonymous
https://en.cppreference.com/w/cpp/language/eval_order This is the point that applies to this particular question. 15) In a function call, value computations and side effects of the initialization of every parameter are indeterminately sequenced with respect to value computations and side effects of any other parameter.
The fact that value computations and side effects of every parameter is indeterminably sequenced is what prevents Undefined Behavior. But this is still Unspecified Behavior as there is no specific order of evaluation of parameters
Manav
Uhh there's too much jargoan with explanations here and none touching the actual problem of interleaved instructions which are largely the root cause of the UB in this case.
Manav
Makes it very difficult for a beginner to follow tbh
Manav
what is the output of int = 1; printf("%d %d %d",a,++a,a++);
The problem is the interleaving of instructions. Consider ++a as an expression, it is often broken up into two instructions temp = a + 1 // evaluate the expression a = temp // move the value to the variable Before C++11, for: fun(++a, ++a); You could have compiler interleave (reorder them) the instructions like this temp1 = a + 1 // value component temp2 = a + 1 // value component a = temp2 // side effect a = temp1 // side effect ... execution of fun(temp1, temp1) After C++11, more robust sequencing of operations for prefix and postfix operarions was introduced. In this case the value component would be sequenced before the side effect but that doesn't solvs the above interleaving problem as you can see for our particular case of what compiler can output After C++17 they are indeterminately sequenced, that is each ++a expression will finish first then the second so temp1 = a + 1 a = temp1 temp2 = a + 1 a = temp2 ... execution of fun(temp1, temp1+temp2) or temp2 = a + 1 a = temp2 temp1 = a + 1 a = temp1 ... execution of fun(temp2, temp1+temp2) can happen. Which makes it implementation defined unspecified behaviour.
Manav
what is the output of int = 1; printf("%d %d %d",a,++a,a++);
So in your case there's six possible outcomes depending on what gets executed first. 1 1 3 if a then a++ then ++a 1 2 2 if a then ++a then a++ 1 2 3 if a++ then a then ++a And so on