The syntax is correct (except for the part that is left out where we cannot anything about it).
Could I use this syntax?
Yes.
Do I need to allocate AA before call pack?
No. Allocatable arrays will be automatically allocated and deallocated when out-of-scope. Regardless of whether the object on the right-hand is the result of any function or something else, e.g. an array of literals.
Is there any risk of using this syntax?
I cannot think of anything risky here.
I guess you are confused about this line
AA=pack([( i,i=1,BB )],mask=CC.GT.0.0)
I will try to explain it:
[( i,i=1,BB )] Builds an array of integers from 1 through 10 by an implied-do loop. Lets call this array B=B(i)
mask=CC.GT.0.0 Only the elements B(i) of the previous array are choosen where CC(i)>0 holds.
pack(...) returns a 1-dimensional array of the previous result.