Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

327
Visualizações
What does `0+ptr` (0 plus a pointer) mean?

I found the following macro in the source code of Perl:

#define GvGP(gv) (0+(gv)->sv_u.svu_gp)

Where sv_u.svu_gp is declared as GP* svu_gp in a union sv_u.

I can't find any definition of GP. However I am more confused about what 0 plus a pointer means. Could anyone enlighten me please?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

I guess it is used to make it an R-value, what makes it read-only in practice.

Example: One can write

x = 1;

but this will not work:

0+x = 1;

Edit

Thanks to Dave Mitchell for pointing a related commit in PERL repository.

add GvCV_set() and GvGP_set() macros.

and make GvCV() and GvGP() rvalue-only. ...

@@ -52,7 +57,8 @@ struct gp {
 #  define GvNAME_get(gv)   ({ assert(GvNAME_HEK(gv)); (char *)HEK_KEY(GvNAME_HEK(gv)); })
 #  define GvNAMELEN_get(gv)    ({ assert(GvNAME_HEK(gv)); HEK_LEN(GvNAME_HEK(gv)); })
 #else
-#  define GvGP(gv) ((gv)->sv_u.svu_gp)
+#  define GvGP(gv) (0+(gv)->sv_u.svu_gp)
+#  define GvGP_set(gv,gp)  ((gv)->sv_u.svu_gp = (gp))
 #  define GvFLAGS(gv)  (GvXPVGV(gv)->xpv_cur)
 #  define GvSTASH(gv)  (GvXPVGV(gv)->xnv_u.xgv_stash)
 #  define GvNAME_HEK(gv)   (GvXPVGV(gv)->xiv_u.xivu_namehek)

Indeed, the purpose was making GvGP read-only by making an r-value.

over 4 years ago · Santiago Trujillo Relatório

0

It makes it an rvalue i.e. you cannot do &(0+(gv)->sv_u.svu_gp); furthermore, if it were instead an array, i.e. 0+"string", it would also decay the array to a char * from a char [7] -- so essentially std::decay.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda